Skip to content

Commit

Permalink
Fix findbugs, pmd and javadoc problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgschmie committed Sep 24, 2013
1 parent ec9bcfa commit 7e13490
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/skife/jdbi/v2/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int[] execute()
{
final long start = System.nanoTime();
final int[] rs = stmt.executeBatch();
final long elapsedTime = (System.nanoTime() - start);
final long elapsedTime = System.nanoTime() - start;
logger.log(elapsedTime / 1000000L);
// Null for statement, because for batches, we don't really have a good way to keep the sql around.
timingCollector.collect(elapsedTime, getContext());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/skife/jdbi/v2/CachingStatementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.skife.jdbi.v2;

import org.skife.jdbi.v2.tweak.StatementBuilder;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -26,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;

import org.skife.jdbi.v2.tweak.StatementBuilder;

/**
* A StatementBuilder which decorates another StatementBuilder and caches
* @deprecated This should be done in the JDBC driver, not here
Expand Down Expand Up @@ -73,6 +73,7 @@ public void close(Connection conn, String sql, Statement stmt) throws SQLExcepti
* Iterate over all cached statements and ask the wrapped StatementBuilder to close
* each one.
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public void close(Connection conn)
{
for (Map.Entry<String,PreparedStatement> statement : cache.entrySet()) {
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/skife/jdbi/v2/ClasspathStatementLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package org.skife.jdbi.v2;

import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException;
import org.skife.jdbi.v2.tweak.StatementLocator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;

import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException;
import org.skife.jdbi.v2.tweak.StatementLocator;

/**
* looks for [name], then [name].sql on the classpath
*/
Expand Down Expand Up @@ -67,6 +68,7 @@ public static boolean looksLikeSql(String sql)
* @throws UnableToCreateStatementException
* if an IOException occurs reading a found resource
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public String locate(String name, StatementContext ctx)
{
final String cache_key;
Expand All @@ -93,7 +95,7 @@ public String locate(String name, StatementContext ctx)
in_stream = loader.getResourceAsStream(name + ".sql");
}

if ((in_stream == null) && (ctx.getSqlObjectType() != null)) {
if (in_stream == null && ctx.getSqlObjectType() != null) {
String filename = '/' + mungify(ctx.getSqlObjectType().getName() + '.' + name) + ".sql";
in_stream = loader.getResourceAsStream(filename);
if (in_stream == null) {
Expand All @@ -107,7 +109,7 @@ public String locate(String name, StatementContext ctx)
}

final StringBuffer buffer = new StringBuffer();
reader = new BufferedReader(new InputStreamReader(in_stream));
reader = new BufferedReader(new InputStreamReader(in_stream, Charset.forName("UTF-8")));
String line;
try {
while ((line = reader.readLine()) != null) {
Expand Down Expand Up @@ -158,11 +160,11 @@ private static boolean isComment(final String line)
return line.startsWith("#") || line.startsWith("--") || line.startsWith("//");
}

private final static String sep = "/"; // *Not* System.getProperty("file.separator"), which breaks in jars
private final static String SEP = "/"; // *Not* System.getProperty("file.separator"), which breaks in jars

private static String mungify(String path)
{
return path.replaceAll("\\.", Matcher.quoteReplacement(sep));
return path.replaceAll("\\.", Matcher.quoteReplacement(SEP));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ String parseString(final String sql, final ParsedStatement stmt) throws IllegalA
case ESCAPED_TEXT:
b.append(t.getText().substring(1));
break;
default:
break;
}
t = lexer.nextToken();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/skife/jdbi/v2/ConcreteStatementContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Binding getBinding()
return binding;
}

public final void setSqlObjectType(Class<?> sqlObjectType)
public void setSqlObjectType(Class<?> sqlObjectType)
{
this.sqlObjectType = sqlObjectType;
}
Expand All @@ -165,7 +165,7 @@ public Class<?> getSqlObjectType()
return sqlObjectType;
}

public final void setSqlObjectMethod(Method sqlObjectMethod)
public void setSqlObjectMethod(Method sqlObjectMethod)
{
this.sqlObjectMethod = sqlObjectMethod;
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/skife/jdbi/v2/DBI.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class DBI implements IDBI
public DBI(DataSource dataSource)
{
this(new DataSourceConnectionFactory(dataSource));
assert (dataSource != null);
assert dataSource != null;
}

/**
Expand All @@ -83,7 +83,7 @@ public DBI(DataSource dataSource)
*/
public DBI(ConnectionFactory connectionFactory)
{
assert (connectionFactory != null);
assert connectionFactory != null;
this.connectionFactory = connectionFactory;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public Connection openConnection() throws SQLException
*/
public void setStatementLocator(StatementLocator locator)
{
assert (locator != null);
assert locator != null;
this.statementLocator.set(locator);
}

Expand All @@ -164,7 +164,7 @@ public StatementLocator getStatementLocator()
*/
public void setStatementRewriter(StatementRewriter rewriter)
{
assert (rewriter != null);
assert rewriter != null;
this.statementRewriter.set(rewriter);
}

Expand All @@ -186,7 +186,7 @@ public StatementRewriter getStatementRewriter()
*/
public void setTransactionHandler(TransactionHandler handler)
{
assert (handler != null);
assert handler != null;
this.transactionhandler.set(handler);
}

Expand Down Expand Up @@ -364,7 +364,7 @@ public void close(Object sqlObject)
*/
public static Handle open(DataSource dataSource)
{
assert (dataSource != null);
assert dataSource != null;
return new DBI(dataSource).open();
}

Expand All @@ -377,7 +377,7 @@ public static Handle open(DataSource dataSource)
*/
public static Handle open(final Connection connection)
{
assert (connection != null);
assert connection != null;
return new DBI(new ConnectionFactory()
{
public Connection openConnection()
Expand All @@ -396,7 +396,7 @@ public Connection openConnection()
*/
public static Handle open(final String url)
{
assert (url != null);
assert url != null;
return new DBI(url).open();
}

Expand All @@ -411,7 +411,7 @@ public static Handle open(final String url)
*/
public static Handle open(final String url, final String username, final String password)
{
assert (url != null);
assert url != null;
return new DBI(url, username, password).open();
}

Expand All @@ -425,7 +425,7 @@ public static Handle open(final String url, final String username, final String
*/
public static Handle open(final String url, final Properties props)
{
assert (url != null);
assert url != null;
return new DBI(url, props).open();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/skife/jdbi/v2/GeneratedKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class GeneratedKeys<Type> implements ResultBearing<Type>
public Type first()
{
try {
if ((results != null) && results.next()) {
if (results != null && results.next()) {
return mapper.map(0, results, context);
}
else {
Expand Down Expand Up @@ -105,7 +105,7 @@ public List<Type> list(int maxRows)
int idx = 0;
List<Type> resultList = new ArrayList<Type>();

if ((results != null) && ++idx <= maxRows && !results.isClosed()) {
if (results != null && ++idx <= maxRows && !results.isClosed()) {
int index = 0;
while (results.next()) {
resultList.add(mapper.map(index++, results, context));
Expand Down Expand Up @@ -164,7 +164,7 @@ public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator, final
try {
AccumulatorType value = accumulator;

if ((results != null) && !results.isClosed()) {
if (results != null && !results.isClosed()) {
while (results.next()) {
value = folder.fold(value, results, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ String parseString(final String sql, final ParsedStatement stmt) throws IllegalA
case ESCAPED_TEXT:
b.append(t.getText().substring(1));
break;
default:
break;
}
t = lexer.nextToken();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/skife/jdbi/v2/Pair.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ final class Pair<FirstType, SecondType>
this.second = second;
}

final FirstType getFirst()
FirstType getFirst()
{
return first;
}

final SecondType getSecond()
SecondType getSecond()
{
return second;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/skife/jdbi/v2/ParsedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ else if (last_token)
tokens.add(token_matcher.group().substring(1, token_matcher.group().length()));
int index = token_matcher.end();
last_token = token_matcher.find();
replaced.append(sql.substring(index, (last_token ? token_matcher.start() : sql.length())));
replaced.append(sql.substring(index, last_token ? token_matcher.start() : sql.length()));
}
else // if (last_quote)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/skife/jdbi/v2/PreparedBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public int[] execute()
try {
final long start = System.nanoTime();
final int[] rs = stmt.executeBatch();
final long elapsedTime = (System.nanoTime() - start);
final long elapsedTime = System.nanoTime() - start;
getLog().logPreparedBatch(elapsedTime / 1000000L, rewritten.getSql(), parts.size());
getTimingCollector().collect(elapsedTime, getContext());

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/skife/jdbi/v2/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public <T> Query<T> map(ResultSetMapper<T> mapper)
* This is useful for doing chunked streaming of results when exhausting memory
* could be a problem.
*
* @param i the number of rows to fetch in a bunch
* @param fetchSize the number of rows to fetch in a bunch
*
* @return the modified query
*/
Expand All @@ -342,7 +342,7 @@ public Query<ResultType> setFetchSize(final int fetchSize)
* Specify the maimum number of rows the query is to return. This uses the underlying JDBC
* {@link Statement#setMaxRows(int)}}.
*
* @param i maximum number of rows to return
* @param maxRows maximum number of rows to return
*
* @return modified query
*/
Expand All @@ -356,7 +356,7 @@ public Query<ResultType> setMaxRows(final int maxRows)
* Specify the maimum field size in the result set. This uses the underlying JDBC
* {@link Statement#setMaxFieldSize(int)}
*
* @param i maximum field size
* @param maxFields maximum field size
*
* @return modified query
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/skife/jdbi/v2/SQLStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public abstract class SQLStatement<SelfType extends SQLStatement<SelfType>> exte
ContainerFactoryRegistry containerFactoryRegistry)
{
super(ctx, foreman);
assert (verifyOurNastyDowncastIsOkay());
assert verifyOurNastyDowncastIsOkay();

addCustomizers(statementCustomizers);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/skife/jdbi/v2/logging/Log4JLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public Log4JLog(Logger log, Priority level) {
}

@Override
protected final boolean isEnabled()
protected boolean isEnabled()
{
return log.isEnabledFor(level);
}

@Override
protected final void log(String msg)
protected void log(String msg)
{
log.log(level, msg);
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/skife/jdbi/v2/sqlobject/BatchHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package org.skife.jdbi.v2.sqlobject;

import com.fasterxml.classmate.members.ResolvedMethod;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import net.sf.cglib.proxy.MethodProxy;

import org.skife.jdbi.v2.ConcreteStatementContext;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.PreparedBatch;
Expand All @@ -10,12 +17,9 @@
import org.skife.jdbi.v2.TransactionStatus;
import org.skife.jdbi.v2.sqlobject.customizers.BatchChunkSize;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import com.fasterxml.classmate.members.ResolvedMethod;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

class BatchHandler extends CustomizingStatementHandler
{
Expand Down Expand Up @@ -96,6 +100,7 @@ public boolean hasNext()
return true;
}

@SuppressFBWarnings("IT_NO_SUCH_ELEMENT")
public Object next()
{
return arg;
Expand Down Expand Up @@ -153,7 +158,7 @@ public void remove()

private int[] executeBatch(final Handle handle, final PreparedBatch batch)
{
if ((!handle.isInTransaction()) && transactional) {
if (!handle.isInTransaction() && transactional) {
// it is safe to use same prepared batch as the inTransaction passes in the same
// Handle instance.
return handle.inTransaction(new TransactionCallback<int[]>()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/skife/jdbi/v2/sqlobject/SqlObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Object intercept(Object o, Method method, Object[] objects, MethodProxy m
}
});
T t = (T) e.create();
factories.putIfAbsent(sqlObjectType, (Factory) t);
return t;
T actual = (T) factories.putIfAbsent(sqlObjectType, (Factory) t);
return actual != null ? actual : t;
}

final SqlObject so = new SqlObject(buildHandlersFor(sqlObjectType), handle);
Expand Down
Loading

0 comments on commit 7e13490

Please sign in to comment.