Skip to content

Commit

Permalink
增加单元测试公共基类;Hibernate升级到4.2;Hibernate Validator升级到5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
think-gem committed May 2, 2013
1 parent 7dde905 commit dc4653b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
30 changes: 9 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
<!-- 依赖库的版本定义 -->
<spring.version>3.2.2.RELEASE</spring.version>
<spring-data-jpa.version>1.3.0.RELEASE</spring-data-jpa.version>
<hibernate.version>4.1.10.Final</hibernate.version>
<hibernate-search.version>4.2.0.Final</hibernate-search.version>
<hibernate.version>4.2.0.Final</hibernate.version>
<druid.version>0.2.16</druid.version>
<sitemesh.version>2.4.2</sitemesh.version>
<shiro.version>1.2.1</shiro.version>
<ehcache.version>2.6.5</ehcache.version>
<hibernate-validator.version>4.3.1.Final</hibernate-validator.version>
<hibernate-validator.version>5.0.1.Final</hibernate-validator.version>
<jackson.version>2.1.4</jackson.version>
<slf4j.version>1.7.2</slf4j.version>
<log4j.version>1.2.17</log4j.version>
Expand All @@ -48,7 +47,7 @@

<!-- Plugin -->
<jdk.version>1.6</jdk.version>
<jetty.version>7.6.9.v20130131</jetty.version>
<jetty.version>7.6.10.v20130312</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>
Expand Down Expand Up @@ -213,12 +212,10 @@
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- hibernate search -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>${hibernate-search.version}</version>
<version>${hibernate.version}</version>
</dependency>
<!-- 中文分词 -->
<dependency>
Expand Down Expand Up @@ -498,29 +495,20 @@
</dependency>

<!-- TEST begin -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- TEST end -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface BaseDao<T> {
* @param parameter
* @return
*/
public int update(String sqlString, Object... parameter);
public int update(String qlString, Object... parameter);

/**
* 创建 QL 查询对象
Expand All @@ -81,7 +81,7 @@ public interface BaseDao<T> {
*/
public Query createQuery(String qlString, Object... parameter);

// -------------- QL Query --------------
// -------------- SQL Query --------------

/**
* SQL 分页查询
Expand All @@ -90,7 +90,7 @@ public interface BaseDao<T> {
* @param parameter
* @return
*/
public Page<T> findBySql(Page<T> page, String qlString, Object... parameter);
public Page<T> findBySql(Page<T> page, String sqlString, Object... parameter);

/**
* SQL 查询
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public List<T> find(String qlString, Object... parameter){

/**
* QL 更新
* @param sqlString
* @param qlString
* @param parameter
* @return
*/
public int update(String sqlString, Object... parameter){
return createQuery(sqlString, parameter).executeUpdate();
public int update(String qlString, Object... parameter){
return createQuery(qlString, parameter).executeUpdate();
}

/**
Expand All @@ -175,22 +175,22 @@ public Query createQuery(String qlString, Object... parameter){
/**
* SQL 分页查询
* @param page
* @param qlString
* @param sqlString
* @param parameter
* @return
*/
@SuppressWarnings("unchecked")
public Page<T> findBySql(Page<T> page, String qlString, Object... parameter){
public Page<T> findBySql(Page<T> page, String sqlString, Object... parameter){
// get count
if (!page.isDisabled() && !page.isNotCount()){
String countQlString = "select count(*)" + removeSelect(removeOrders(qlString));
String countQlString = "select count(*)" + removeSelect(removeOrders(sqlString));
page.setCount((Long)createSqlQuery(countQlString, parameter).getSingleResult());
if (page.getCount() < 1) {
return page;
}
}
// order by
String ql = qlString;
String ql = sqlString;
if (StringUtils.isNotBlank(page.getOrderBy())){
ql += " order by " + page.getOrderBy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.thinkgem.jeesite.common.test;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

@ActiveProfiles("production")
@ContextConfiguration(locations = {"/applicationContext.xml", "/applicationContext-shiro.xml"})
public class SpringTransactionalContextTests extends AbstractTransactionalJUnit4SpringContextTests {

protected DataSource dataSource;

@Autowired
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
this.dataSource = dataSource;
}

}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jdbc.password=123456

#oracle database settings
#jdbc.driver=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:gem
#jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
#jdbc.username=jeesite
#jdbc.password=jeesite
#jdbc.password=123456

#h2 database settings
#jdbc.driver=org.h2.Driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!DOCTYPE html>
<html style="overflow-x:hidden;overflow-y:auto;">
<head>
<title>栏目列表</title>
<title>数据选择</title>
<%@include file="/WEB-INF/views/include/head.jsp" %>
<%@include file="/WEB-INF/views/include/treeview.jsp" %>
<script type="text/javascript">
Expand Down

0 comments on commit dc4653b

Please sign in to comment.