Commits

Danny van Bruggen committed 306c186

* Format code

  • Participants
  • Parent commits 88dcd56

Comments (0)

Files changed (10)

File hql-queryprutser/src/main/java/com/laamella/queryprutser/Assert.java

 package com.laamella.queryprutser;
 
 public final class Assert {
-	private Assert(){
+	private Assert() {
 		// Singleton.
 	}
-	public static void notNull(Object value) {
+
+	public static void notNull(final Object value) {
 		if (value == null) {
 			throw new AssertionError("Value was null");
 		}

File hql-queryprutser/src/main/java/com/laamella/queryprutser/Clause.java

 	/**
 	 * "Normal" constructor.
 	 * 
-	 * @param prefix a piece of text to put at the start of the eventual string.
-	 * @param infix a piece of text to put inbetween each piece of text added.
-	 * @param postfix a piece of text to put at the end of the eventual string, but only if the eventual string isn't empty.
+	 * @param prefix
+	 *            a piece of text to put at the start of the eventual string.
+	 * @param infix
+	 *            a piece of text to put inbetween each piece of text added.
+	 * @param postfix
+	 *            a piece of text to put at the end of the eventual string, but
+	 *            only if the eventual string isn't empty.
 	 */
-	Clause(String prefix, String infix, String postfix) {
+	Clause(final String prefix, final String infix, final String postfix) {
 		this(prefix, infix, postfix, true, new StringBuilder());
 	}
 
 	/**
 	 * Makes this {@link Clause} a copy of source.
 	 */
-	Clause(Clause source) {
+	Clause(final Clause source) {
 		this(source.prefix, source.infix, source.postfix, source.firstAppend, new StringBuilder(source.builder));
 	}
 
-	private Clause(String prefix, String infix, String postfix, boolean firstAppend, StringBuilder builder) {
+	private Clause(final String prefix, final String infix, final String postfix, final boolean firstAppend, final StringBuilder builder) {
 		Assert.notNull(prefix);
 		Assert.notNull(infix);
 		Assert.notNull(postfix);
 	 * 
 	 * @return this
 	 */
-	public Clause add(String text) {
+	public Clause add(final String text) {
 		return addWithSpecialInfix(infix, text);
 	}
 
 	 * 
 	 * @return this
 	 */
-	public Clause add(String... texts) {
+	public Clause add(final String... texts) {
 		return addWithSpecialInfix(infix, texts);
 	}
 
 	/**
-	 * Adds one piece of text, taking care to insert pre, in, and postfixes, overriding the infix for just this once.
+	 * Adds one piece of text, taking care to insert pre, in, and postfixes,
+	 * overriding the infix for just this once.
 	 * 
 	 * @return this
 	 */
-	public Clause addWithSpecialInfix(String specialInfix, String text) {
+	public Clause addWithSpecialInfix(final String specialInfix, final String text) {
 		Assert.notNull(specialInfix);
 		Assert.notNull(text);
 		if (!firstAppend) {
 	 * 
 	 * @return this
 	 */
-	public Clause addWithSpecialInfix(String specialInfix, String... texts) {
-		for (String text : texts) {
+	public Clause addWithSpecialInfix(final String specialInfix, final String... texts) {
+		for (final String text : texts) {
 			addWithSpecialInfix(specialInfix, text);
 		}
 		return this;

File hql-queryprutser/src/main/java/com/laamella/queryprutser/ClauseWithSubselects.java

 package com.laamella.queryprutser;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class ClauseWithSubselects extends Clause {
 	private final List<Subquery> subqueries = new ArrayList<Subquery>();
 
-	ClauseWithSubselects(String prefix, String infix, String postfix) {
+	ClauseWithSubselects(final String prefix, final String infix, final String postfix) {
 		super(prefix, infix, postfix);
 	}
 
-	public Subquery subselect(Class<?> rootClass, String alias) {
-		Subquery subquery = new Subquery(rootClass, alias);
+	public Subquery subselect(final Class<?> rootClass, final String alias) {
+		final Subquery subquery = new Subquery(rootClass, alias);
 		subqueries.add(subquery);
 		return subquery;
 	}
 
-	public Subquery subselect(Class<?> rootClass) {
+	public Subquery subselect(final Class<?> rootClass) {
 		return subselect(rootClass, null);
 	}
 
 	@Override
 	public String toString() {
-		Clause privateClause = new Clause(this);
-		for (Subquery builder : subqueries) {
+		final Clause privateClause = new Clause(this);
+		for (final Subquery builder : subqueries) {
 			privateClause.add(" " + builder.queryString() + " ");
 		}
 		return privateClause.toString();
 	}
 
-	void putAllParametersInThisMap(Map<String, Object> inHere) {
-		for (Subquery subquery : subqueries) {
+	void putAllParametersInThisMap(final Map<String, Object> inHere) {
+		for (final Subquery subquery : subqueries) {
 			inHere.putAll(subquery.allParameters());
 		}
 	}

File hql-queryprutser/src/main/java/com/laamella/queryprutser/FromClause.java

 package com.laamella.queryprutser;
 
 public class FromClause extends Clause {
-	FromClause(Class<?> rootClass, String alias) {
+	FromClause(final Class<?> rootClass, final String alias) {
 		super("from ", " ", " ");
 		Assert.notNull(rootClass);
 		if (alias != null) {
 		}
 	}
 
-	public FromClause joinFetch(String relationship, String alias) {
+	public FromClause joinFetch(final String relationship, final String alias) {
 		add("join fetch " + relationship + " " + alias);
 		return this;
 	}

File hql-queryprutser/src/main/java/com/laamella/queryprutser/QueryBuilder.java

 import org.slf4j.LoggerFactory;
 
 /**
- * Simple helper for building dynamic HQL select queries, as opposed to Criteria, which are more helpful, complex, and contain many
- * gotcha's, and to plain HQL, which is not dynamic.
+ * Simple helper for building dynamic HQL select queries, as opposed to
+ * Criteria, which are more helpful, complex, and contain many gotcha's, and to
+ * plain HQL, which is not dynamic.
  */
 public class QueryBuilder {
 	private final Logger log = LoggerFactory.getLogger(QueryBuilder.class);
 
 	private final Map<String, Object> parameters = new HashMap<String, Object>();
 
-	public QueryBuilder(Class<?> rootClass, String alias) {
+	public QueryBuilder(final Class<?> rootClass, final String alias) {
 		from = new FromClause(rootClass, alias);
 	}
 
-	public QueryBuilder(Class<?> rootClass) {
+	public QueryBuilder(final Class<?> rootClass) {
 		this(rootClass, null);
 	}
 
-	public QueryBuilder orderBy(String... fields) {
+	public QueryBuilder orderBy(final String... fields) {
 		orderBy.add(fields);
 		return this;
 	}
 
-	public QueryBuilder groupBy(String... fields) {
+	public QueryBuilder groupBy(final String... fields) {
 		groupBy.add(fields);
 		return this;
 	}
 
-	public QueryBuilder select(String... fields) {
+	public QueryBuilder select(final String... fields) {
 		select.add(fields);
 		return this;
 	}
 	 * 
 	 * @return
 	 */
-	public QueryBuilder parameter(String name, Object value) {
+	public QueryBuilder parameter(final String name, final Object value) {
 		Assert.notNull(name);
 		parameters.put(name, value);
 		return this;
 	/**
 	 * @return create the final query.
 	 */
-	public Query query(Session session) {
-		String hql = queryString().toString();
+	public Query query(final Session session) {
+		final String hql = queryString().toString();
 		log.debug(hql);
-		Query query = session.createQuery(hql);
-		Map<String, Object> allParameters = allParameters();
+		final Query query = session.createQuery(hql);
+		final Map<String, Object> allParameters = allParameters();
 
-		for (Map.Entry<String, Object> entry : allParameters.entrySet()) {
+		for (final Map.Entry<String, Object> entry : allParameters.entrySet()) {
 			log.debug(entry.getKey() + "=" + entry.getValue());
 			query.setParameter(entry.getKey(), entry.getValue());
 		}

File hql-queryprutser/src/main/java/com/laamella/queryprutser/SelectClause.java

 		super("select ", ", ", " ");
 	}
 
-	public void min(String string) {
+	public void min(final String string) {
 		add("min(" + string + ")");
 	}
 
-	public void max(String string) {
+	public void max(final String string) {
 		add("max(" + string + ")");
 	}
 }

File hql-queryprutser/src/main/java/com/laamella/queryprutser/Subquery.java

 	private String before = "";
 	private String after = "";
 
-	Subquery(Class<?> rootClass, String alias) {
+	Subquery(final Class<?> rootClass, final String alias) {
 		super(rootClass, alias);
 	}
 
-	public Subquery before(String before) {
+	public Subquery before(final String before) {
 		Assert.notNull(before);
 		this.before = before;
 		return this;
 	}
 
-	public Subquery after(String after) {
+	public Subquery after(final String after) {
 		Assert.notNull(after);
 		this.after = after;
 		return this;

File hql-queryprutser/src/main/java/com/laamella/queryprutser/WhereClause.java

 		this("where");
 	}
 
-	protected WhereClause(String keyword) {
+	protected WhereClause(final String keyword) {
 		super(" \n" + keyword + " ", "\n", " ");
 	}
 
-	public void and(String... values) {
+	public void and(final String... values) {
 		addWithSpecialInfix("\nand ", values);
 	}
 }

File hql-queryprutser/src/test/java/com/laamella/queryprutser/ClauseTest.java

 
 import org.junit.Test;
 
-import com.laamella.queryprutser.Clause;
-
 public class ClauseTest {
 
 	@Test
 	public void whenNotAppendingAnythingThenResultIsEmpty() {
-		Clause string = new Clause("pre", "in", "post");
+		final Clause string = new Clause("pre", "in", "post");
 		assertEquals("", string.toString());
 	}
 
 	@Test
 	public void whenAppendingOneThingThenPreAndPostfixAreAdded() {
-		Clause string = new Clause("pre", "in", "post");
+		final Clause string = new Clause("pre", "in", "post");
 		string.add("text");
 		assertEquals("pretextpost", string.toString());
 	}
 
 	@Test
 	public void whenAppendingSeveralThingsThenPreInAndPostfixAreAdded() {
-		Clause string = new Clause("pre", "in", "post");
+		final Clause string = new Clause("pre", "in", "post");
 		string.add("text1", "text2", "text3");
 		assertEquals("pretext1intext2intext3post", string.toString());
 	}

File hql-queryprutser/src/test/java/com/laamella/queryprutser/QueryBuilderTest.java

 package com.laamella.queryprutser;
 
 import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 import java.util.Map;
 
 import org.hibernate.Session;
 import org.junit.Test;
 
-import com.laamella.queryprutser.QueryBuilder;
-import com.laamella.queryprutser.Subquery;
-
 public class QueryBuilderTest {
 	@Test
 	public void whenNothingIsDoneWithQueryBuilderThenWeGetASelectEverything() {
-		QueryBuilder queryBuilder = new QueryBuilder(Object.class);
+		final QueryBuilder queryBuilder = new QueryBuilder(Object.class);
 		assertEquals(0, queryBuilder.allParameters().size());
 		assertFuzzyString("from java.lang.Object", queryBuilder.queryString());
 	}
 
 	@Test
 	public void whenTheRootObjectIsAliasedThenItShowsInTheHql() {
-		QueryBuilder queryBuilder = new QueryBuilder(Object.class, "o");
+		final QueryBuilder queryBuilder = new QueryBuilder(Object.class, "o");
 		assertFuzzyString("from java.lang.Object o", queryBuilder.queryString());
 	}
 
 	@Test
 	public void whenDoingAnAliasedJoinFetchThenWeGetThat() {
-		QueryBuilder queryBuilder = new QueryBuilder(Object.class);
+		final QueryBuilder queryBuilder = new QueryBuilder(Object.class);
 		queryBuilder.from.joinFetch("relationship", "rel");
 		assertFuzzyString("from java.lang.Object join fetch relationship rel", queryBuilder.queryString());
 	}
 
 	@Test
-	public void whenPuttingASubqueryIntoTheSelectClauseThenItIsThere(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenPuttingASubqueryIntoTheSelectClauseThenItIsThere() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.select.subselect(String.class);
 		assertFuzzyString("select (from java.lang.String ) from java.lang.Object", builder.queryString());
 	}
 
 	@Test
-	public void whenPuttingASubqueryIntoTheWhereClauseThenItIsThere(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenPuttingASubqueryIntoTheWhereClauseThenItIsThere() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.where.subselect(String.class);
 		assertFuzzyString("from java.lang.Object where (from java.lang.String )", builder.queryString());
 	}
+
 	@Test
-	public void whenGivingASubqueryABeforeAndAfterStringThenTheyAreThere(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
-		Subquery subselect = builder.where.subselect(String.class);
+	public void whenGivingASubqueryABeforeAndAfterStringThenTheyAreThere() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
+		final Subquery subselect = builder.where.subselect(String.class);
 		subselect.before(">>>");
 		subselect.after("<<<");
 		assertFuzzyString("from java.lang.Object where >>>(from java.lang.String ) <<<", builder.queryString());
 	}
 
 	@Test
-	public void whenUsingAllClausesThenTheyAreInTheRightOrder(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenUsingAllClausesThenTheyAreInTheRightOrder() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.select.add("[select clause]");
 		builder.from.add("[from clause]");
 		builder.where.add("[where clause]");
 		builder.orderBy("[order by clause]");
 		builder.groupBy("[group by clause]");
 		builder.having.add("[having clause]");
-		assertFuzzyString("select [select clause] from java.lang.Object [from clause] where [where clause] group by [group by clause] having [having clause] order by [order by clause]", builder.queryString());
+		assertFuzzyString("select [select clause] from java.lang.Object [from clause] where [where clause] group by [group by clause] having [having clause] order by [order by clause]",
+				builder.queryString());
 	}
-	
+
 	@Test
-	public void whenUsingMinMaxThenThoseAreAdded(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenUsingMinMaxThenThoseAreAdded() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.select.max("a");
 		builder.select.min("b");
 		assertFuzzyString("select max(a), min(b) from java.lang.Object", builder.queryString());
 	}
-	
+
 	@Test
-	public void whenSelectingMoreThanOneThingThenTheRightInfixesAreUsed(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenSelectingMoreThanOneThingThenTheRightInfixesAreUsed() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.select("abc", "def", "ghi");
 		assertFuzzyString("select abc, def, ghi from java.lang.Object", builder.queryString());
 	}
 
 	@Test
-	public void whenWhereingMoreThanOneThingThenTheRightInfixesAreUsed(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenWhereingMoreThanOneThingThenTheRightInfixesAreUsed() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.where.and("abc", "def", "ghi");
 		assertFuzzyString("from java.lang.Object where abc and def and ghi", builder.queryString());
 	}
-	
+
 	@Test
-	public void whenSettingParametersAllOverThePlaceThenTheyAreAllCollected(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenSettingParametersAllOverThePlaceThenTheyAreAllCollected() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.parameter("a", "a");
 		builder.select.subselect(String.class).parameter("b", "b");
 		builder.where.subselect(Integer.class).having.subselect(Float.class).parameter("c", "c");
-		Map<String, Object> allParameters = builder.allParameters();
-		
+		final Map<String, Object> allParameters = builder.allParameters();
+
 		assertEquals(3, allParameters.size());
 		assertEquals("a", allParameters.get("a"));
 		assertEquals("b", allParameters.get("b"));
 		assertEquals("c", allParameters.get("c"));
 	}
-	
+
 	@Test
-	public void whenCallingToStringThenTheHqlIsReturned(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenCallingToStringThenTheHqlIsReturned() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		assertFuzzyString("from java.lang.Object", builder.toString());
 	}
-	
+
 	@Test
-	public void whenCreatingAHibernateQueryThenTheRightHqlAndAllParametersAreSet(){
-		QueryBuilder builder = new QueryBuilder(Object.class);
+	public void whenCreatingAHibernateQueryThenTheRightHqlAndAllParametersAreSet() {
+		final QueryBuilder builder = new QueryBuilder(Object.class);
 		builder.parameter("a", "a");
-		Session sessionMock=mock(Session.class);
-		Query queryMock=mock(Query.class);
+		final Session sessionMock = mock(Session.class);
+		final Query queryMock = mock(Query.class);
 		when(sessionMock.createQuery("from java.lang.Object ")).thenReturn(queryMock);
 
-		Query query = builder.query(sessionMock);
+		final Query query = builder.query(sessionMock);
 		assertEquals(queryMock, query);
 		verify(queryMock).setParameter("a", "a");
 	}
 
-	private void assertFuzzyString(CharSequence expected, CharSequence actual) {
+	private void assertFuzzyString(final CharSequence expected, final CharSequence actual) {
 		assertEquals(cleanString(expected), cleanString(actual));
 	}
-	
-	private String cleanString(CharSequence actual){
-		String[] split = actual.toString().split("\\s+");
-		StringBuffer stringBuffer = new StringBuffer();
-		for(String s: split){
+
+	private String cleanString(final CharSequence actual) {
+		final String[] split = actual.toString().split("\\s+");
+		final StringBuffer stringBuffer = new StringBuffer();
+		for (final String s : split) {
 			stringBuffer.append(s);
 			stringBuffer.append(" ");
 		}