Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
Added checkstyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenobu committed Nov 25, 2012
1 parent 1319ad2 commit 0db17a3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 25 deletions.
47 changes: 47 additions & 0 deletions checkstyle.xml
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">

<module name="RegexpSingleline">
<!-- \s matches whitespace character, $ matches end of line. -->
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<module name="TreeWalker">

<property name="cacheFile" value="${checkstyle.cache.file}"/>

<!-- ensure we have tabs only -->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* +\t*\S"/>
<property name="message" value="Line has leading space characters; indentation should be performed with tabs only."/>
<property name="ignoreComments" value="true"/>
</module>

<!-- Modifier Checks -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for common coding problems -->
<!-- Disabled until http://sourceforge.net/tracker/?func=detail&aid=2843447&group_id=29721&atid=397078 is fixed-->
<!--<module name="DoubleCheckedLocking"/>-->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="RedundantThrows">
<property name="allowUnchecked" value="true"/>
</module>

<!-- Miscellaneous other checks. -->
<module name="UpperEll"/>
<module name="PackageAnnotation"/>
<module name="CovariantEquals"/>
<module name="ArrayTypeStyle"/>

</module>

</module>
29 changes: 29 additions & 0 deletions pom.xml
Expand Up @@ -30,6 +30,35 @@
<target>1.6</target>
</configuration>
</plugin>
<!-- Checkstyle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<failsOnError>false</failsOnError>
<useFile/>
</configuration>
<executions>
<execution>
<id>check-style</id>
<phase>compile</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
<execution>
<id>test-check-style</id>
<phase>test-compile</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Expand Up @@ -21,40 +21,40 @@ public abstract class AbstractJdbcRepository<T extends Persistable<ID>,ID extend
private JdbcTemplate jdbcTemplate;
private String tableName;
private String idColumn;

private final String deleteQuery;
private final String selectAll;
private final String selectById;
private final String countQuery;

RowMapper<T> rowMapper;
Updater<T> updater;

public interface Updater<T> {
public void mapColumns(T t,Map<String,Object> mapping);
public void mapColumns(T t,Map<String,Object> mapping);
}

public AbstractJdbcRepository(
RowMapper<T> rowMapper,
Updater<T> updater,
String tableName,
String idColumn,
JdbcTemplate jdbcTemplate) {

this.updater = updater;
this.rowMapper = rowMapper;

this.jdbcTemplate = jdbcTemplate;
this.tableName = tableName;
this.idColumn = idColumn;

this.deleteQuery = String.format("delete from %s where %s = ?",tableName,idColumn);
this.selectAll = String.format("select * from %s",tableName);
this.selectById = String.format("select * from %s where %s = ?",tableName,idColumn);
this.countQuery = String.format("select count(%s) from %s",idColumn, tableName);

}

@Override
public long count() {
return jdbcTemplate.queryForLong(this.countQuery);
Expand Down Expand Up @@ -106,22 +106,22 @@ public T save(T entity) {
updater.mapColumns(entity, columns);

String updateQuery = String.format("update %s set ",this.tableName);

Object[] obj = new Object[columns.size()];
int i = 0;

for(Map.Entry<String,Object> e : columns.entrySet())
{
obj[i++] = e.getValue();
updateQuery += " " + e.getKey() + " = ? ";
updateQuery += " " + e.getKey() + " = ? ";
}

obj[i] = entity.getId();

updateQuery += String.format(" where %s = ? ",this.idColumn);
jdbcTemplate.update(updateQuery,obj);

jdbcTemplate.update(updateQuery,obj);

return entity;
}

Expand All @@ -138,12 +138,12 @@ public Iterable<T> save(Iterable<? extends T> entities) {
@Override
public Iterable<T> findAll(Sort sort) {
String qu = this.selectAll;

for(Order o : sort)
{
qu += " ORDER BY " + o.getProperty() + " " + o.getDirection().toString() + " ";
}

return jdbcTemplate.query(qu,this.rowMapper);
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/springframework/data/jdbc/User.java
Expand Up @@ -8,9 +8,9 @@ public class User implements Persistable<String> {

private String userName;
private String password;

private String fullName;

private String role;

protected void setUserName(String userName) {
Expand Down Expand Up @@ -48,7 +48,7 @@ public String getRole() {
public User(
String id,
String userName,
String password,
String password,
String fullName,
String role) {
this.id = id;
Expand Down
Expand Up @@ -30,10 +30,10 @@ public User mapRow(ResultSet rs, int rowNum) throws SQLException {
rs.getString("userName"),
rs.getString("password"),
rs.getString("fullName"),
rs.getString("role"));
rs.getString("role"));
}
};

static Updater<User> userUpdaterMapper = new Updater<User>() {
@Override
public void mapColumns(User t, Map<String, Object> mapping) {
Expand Down

0 comments on commit 0db17a3

Please sign in to comment.