`

SpringMVC3.2.x + Hibernate4.2.x + ecache

 
阅读更多
附件是源码

pom.xml
------------------------------------------------
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.pandy</groupId>
	<artifactId>JBPM5sh</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>ssm3 Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<properties>
		<spring.version>3.2.2.RELEASE</spring.version>
		<spring.jdbc.version>3.2.2.RELEASE</spring.jdbc.version>
		<aspectj.version>1.6.10</aspectj.version>
		<jetty.version>6.1.26</jetty.version>
		<tomcat.version>2.0</tomcat.version>
		<junit.version>4.11</junit.version>
		<mysql.version>5.1.25</mysql.version>
		<jtds.version>1.2.4</jtds.version>
		<hibernate.version>4.2.1.Final</hibernate.version>
                <hibernateCommAnn.version>3.2.0.Final</hibernateCommAnn.version>
		<hibernateAnn.version>3.5.6-Final</hibernateAnn.version>
		<cglib.version>2.2.2</cglib.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>${mysql.version}</version>
		</dependency>

		<!-- JBOSS Cache & Hibernate -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-ehcache</artifactId>
			<version>4.2.1.Final</version>
		</dependency>
		<dependency>
			<groupId>hsqldb</groupId>
			<artifactId>hsqldb</artifactId>
			<version>1.8.0.4</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-testing</artifactId>
			<version>${hibernate.version}</version>
		</dependency>
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache-core</artifactId>
			<version>2.4.3</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit.version}</version>
			<scope>test</scope>
		</dependency>

		<!-- Spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.jdbc.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.jdbc.version}</version>
		</dependency>


		<!-- Hibernate -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>${hibernate.version}</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-entitymanager</artifactId>
			<version>${hibernate.version}</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-commons-annotations</artifactId>
			<version>${hibernateCommAnn.version}</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-annotations</artifactId>
			<version>${hibernateAnn.version}</version>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>${cglib.version}</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>

		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<version>1.8.3</version>
		</dependency>

		<!-- Log4j -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.lazyluke</groupId>
			<artifactId>log4jdbc-remix</artifactId>
			<version>0.2.7</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>JBPM5sh</finalName>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>maven-jetty-plugin</artifactId>
					<version>${jetty.version}</version>
				</plugin>
				<plugin>
					<groupId>org.apache.tomcat.maven</groupId>
					<artifactId>tomcat6-maven-plugin</artifactId>
					<version>${tomcat.version}</version>
				</plugin>
				<plugin>
					<!-- 注解支持,jdk5才具有的新特性,我们需要设置compile插件,具体可以参考Setting the -source and 
						-target of the Java Compiler,根据说明,我们继续向pom文件中加入 -->
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<configuration>
						<source>5</source>
						<target>5</target>
					</configuration>
				</plugin>
				<plugin>
					<!-- 我们想将所有的依赖库都打包,直接交给用户,这样用户不需要在做其他设置了,这里需要使用Assembly插件了,其说明参考Pre-defined 
						Descriptor Files,这个参考文件也说明了有四种默认定义的打包方式,我们选择jar-with-dependencies,继续添加pom文件 -->
					<artifactId>maven-assembly-plugin</artifactId>
					<configuration>
						<descriptorRefs>
							<descriptorRef>jar-with-dependencies</descriptorRef>
						</descriptorRefs>
					</configuration>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-dependency-plugin</artifactId>
					<executions>
						<execution>
							<id>copy</id>
							<phase>install</phase>
							<goals>
								<goal>copy-dependencies</goal>
							</goals>
							<configuration>
								<outputDirectory>$/lib</outputDirectory>
								<!-- 拷贝所以依赖存放位置 -->
							</configuration>
						</execution>
					</executions>
				</plugin>
			</plugins>

		</pluginManagement>
	</build>

</project> 




SQL
--------------------------------------------------------------------
CREATE TABLE
    TABLE3
    (
        id INT auto_increment NOT NULL,
        name VARCHAR(90),
        password VARCHAR(90),
        email VARCHAR(90),
        PRIMARY KEY (id)
    )
    ENGINE=InnoDB DEFAULT CHARSET=latin1;

   
   
    web.xml
    ------------------------------------------------------
   <!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
	<display-name>Archetype Created Web Application</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<servlet>
		<servlet-name>JBPM5sh</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>JBPM5sh</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	<!-- <filter>
		<filter-name>openSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
	</filter> -->
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

</web-app>



src/main/resources/applicationContext.xml
--------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/context         
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx         
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
	default-autowire="byName" default-lazy-init="true">

	<context:component-scan base-package="com">
		<context:exclude-filter expression="org.springframework.stereotype.Controller"
			type="annotation" />
	</context:component-scan>
	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:jdbc.properties</value>
		</property>
	</bean>

	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
		p:packagesToScan="com.pandy.ssh4.domian">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					${hibernate.dialect}
				</prop>
				<prop key="hibernate.show_sql">false</prop>
				<prop key="hibernate.format_sql">false</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
				<prop key="hibernate.cache.use_structured_entries">true</prop>
				<prop key="hibernate.generate_statistics">true</prop>
			</props>
		</property>
	</bean>
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />
</beans>	



JBPM5sh-servlet.xml
------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<context:component-scan base-package="com">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository" />
    </context:component-scan>

	<mvc:annotation-driven/>

	<mvc:resources location="/resources/" mapping="/resources/**"/> 
	
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<property name="prefix" value="/"></property>
    	<property name="suffix" value=".jsp"></property>
    </bean>

</beans>



src/main/resources/ehcache.xml
-------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
	<!--如果缓存中的对象存储超过指定的缓存数量的对象存储的磁盘地址 -->
	<diskStore path="D:/ehcache" />

	<!-- 默认cache:如果没有对应的特定区域的缓存,就使用默认缓存 -->
	<defaultCache maxElementsInMemory="10000" eternal="false"
		timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false" />
		
		
	<!-- 指定区域cache:通过name指定,name对应到Hibernate中的区域名即可 -->
	<cache name="cn.javass.h3test.model.UserModel" eternal="false"
		maxElementsInMemory="100" timeToIdleSeconds="1200" timeToLiveSeconds="1200"
		overflowToDisk="false">
	</cache>

</ehcache>

这个是缓存配置




src/main/resources/jdbc.properties
---------------------------------------------------------
jdbc.driver=net.sf.log4jdbc.DriverSpy
jdbc.url=jdbc:log4jdbc:mysql://localhost:3306/jbpmtest?createDatabaseIfNotExist=true
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/jbpmtest?createDatabaseIfNotExist=true

jdbc.username=root
jdbc.password=root
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect




src/main/resources/log4j.properties
----------------------------------------------------
log4j.rootLogger=WARN, stdout
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# log4jdbc
log4j.logger.jdbc.sqlonly=INFO 
log4j.logger.jdbc.sqltiming=INFO
log4j.logger.jdbc.audit=OFF
log4j.logger.jdbc.resultset=OFF
log4j.logger.jdbc.connection=OFF



src/main/java/com/pandy/ssh4/domian/BasicDomian.java
--------------------------------------------------------------------------------------
package com.pandy.ssh4.domian;

import java.io.Serializable;

@SuppressWarnings("serial")
public abstract class BasicDomian implements Serializable {

	public String getDomainName() {
		return getClass().getName();
	}

	public abstract String getIdName();

}



src/main/java/com/pandy/ssh4/domian/Table3.java
------------------------------------------------------
package com.pandy.ssh4.domian;

// Generated 2013-3-7 17:34:40 by Hibernate Tools 4.0.0

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * Table3 generated by hbm2java
 */
@SuppressWarnings("serial")
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)  
@Table(name = "TABLE3")
public class Table3 extends BasicDomian implements java.io.Serializable {

	private int id;
	private String name;
	private String password;
	private String email;

	public Table3() {
	}

	public Table3(int id) {
		this.id = id;
	}

	public Table3(int id, String name, String password, String email) {
		this.id = id;
		this.name = name;
		this.password = password;
		this.email = email;
	}

	@Id
	@GeneratedValue
	@Column(name = "ID", unique = true, nullable = false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "NAME", length = 1000)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "PASSWORD", length = 1000)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "EMAIL", length = 1000)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Transient
	@Override
	public String getIdName() {
		return "id";
	}

	@Override
	public String toString() {
		return "Table3 [id=" + id + ", name=" + name + ", password=" + password
				+ ", email=" + email + "]";
	}

}




src/main/java/com/pandy/ssh4/dao/BasicDao.java
----------------------------------------------------------------------------
package com.pandy.ssh4.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

@SuppressWarnings("rawtypes")
public abstract class BasicDao extends HibernateDaoSupport  {

	@Autowired
	public void setSessionFactoryOverride(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	public Session getCurrentSession(){
		return getSessionFactory().getCurrentSession();
	}

	public List listAll(String domianName) {
		Session session = super.getSessionFactory().getCurrentSession();
		Query query = session.createQuery("from com.pandy.ssh4.domian."
				+ domianName + " t");
		List list = query.list();
		return list;
	}

	public void save(Object o) {
		Session session = getSessionFactory().getCurrentSession();
		session.save(o);
	}

	public void saveOrUpdate(Object o) {
		Session session = getSessionFactory().getCurrentSession();
		session.saveOrUpdate(o);
	}

	public void delete(Object o) {
		try {
			Session session = getSessionFactory().getCurrentSession();
			session.delete(o);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}

	}
}



src/main/java/com/pandy/ssh4/dao/impl/Table3Dao.java
----------------------------------------------------------------
package com.pandy.ssh4.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.stat.Statistics;
import org.springframework.stereotype.Repository;

import com.pandy.ssh4.dao.BasicDao;

@Repository
public class Table3Dao extends BasicDao {

	@SuppressWarnings("rawtypes")
	public void doEhcache1() {

		Session session = getCurrentSession();
		String hql = " from com.pandy.ssh4.domian.Table3";
		Query query = session.createQuery(hql);
		query.setCacheable(true);//设定使用缓存
		List list = query.list();
		System.out.println(list.size());
	}

	@SuppressWarnings("rawtypes")
	public void doEhcache2() {

		Session session = getCurrentSession();
		String hql = " from com.pandy.ssh4.domian.Table3";
		Query query = session.createQuery(hql);
		query.setCacheable(true);//设定使用缓存

		List list = query.list();
		System.out.println(list.size());
	}

	public void printCacheInfo() {
		Statistics s = getSessionFactory().getStatistics();
		System.out.println(s);
		System.out.println("put:" + s.getSecondLevelCachePutCount());
		System.out.println("hit:" + s.getSecondLevelCacheHitCount());
		System.out.println("miss:" + s.getSecondLevelCacheMissCount());
	}

}

注意,query.setCacheable(true);//设定使用缓存是设定了缓存

src/main/java/com/pandy/ssh4/service/SampleService.java
-------------------------------------------------------------
package com.pandy.ssh4.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pandy.ssh4.dao.BasicDao;
import com.pandy.ssh4.dao.impl.Table3Dao;
import com.pandy.ssh4.domian.Table3;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class SampleService {
	@Resource(name = "table3Dao")
	public Table3Dao table3Dao;

	/**
	 * 对单表增、删、改应用方式文字描述和示例
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
	public void sample1() {

		// 增加
		Table3 domain = new Table3();
		domain.setName("pandy");
		domain.setEmail("panyongzheng@163.com");
		table3Dao.save(domain);
		System.out.println("----------------------------------------增加完成");
		validation(table3Dao);

		// 修改
		domain.setName("New Name");
		table3Dao.saveOrUpdate(domain);
		System.out.println("----------------------------------------修改完成");
		validation(table3Dao);

		// 删除
		table3Dao.delete(domain);
		System.out.println("----------------------------------------删除完成 id=" + domain.getId());
		validation(table3Dao);

	}

	/**
	 * 对单表查询的应用方式文字描述和示例?
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
	public void sample3() {
		System.out.println("----------------------------------------增加两个记录来测试缓存");
		Table3 domain1 = new Table3();
		domain1.setName("pandy1");
		domain1.setEmail("panyongzheng@163.com");
		table3Dao.save(domain1);
		Table3 domain2 = new Table3();
		domain2.setName("pandy2");
		domain2.setEmail("panyongzheng@163.com");
		table3Dao.save(domain2);
		System.out.println("----------------------------------------增加两个记录信息");
		List list = table3Dao.listAll("Table3");
		for (Object o : list) {
			System.out.println("listAll->	" + o.toString());
		}

	}

	@Transactional(propagation = Propagation.REQUIRED)
	public void validation(BasicDao dao) {
		String className = dao.getClass().getName();
		className = className.substring(className.lastIndexOf(".") + 1,
				className.indexOf("Dao"));
		List list = dao.listAll(className);
		for (Object o : list) {
			System.out.println("	" + o.toString());
		}
		System.out.println("验证完成");
	}


	@Transactional(propagation = Propagation.REQUIRED)
	public void doEhcache() {
		System.out.println("---------------第一次查询--------------------");
		table3Dao.doEhcache1();
		System.out.println("---------------第二次查询--------------------");
		table3Dao.doEhcache2();
		System.out.println("---------------缓存信息--------------------");
		table3Dao.printCacheInfo();
	}

	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
	public void listAll() {

		Table3 t = new Table3();
		t.setName("panyongzheng");
		table3Dao.save(t);

		List list = table3Dao.listAll("Table3");
		for (Object o : list) {
			System.out.println(o.toString());
		}

	}
}


   

src/main/java/com/pandy/ssh4/controller/TestController.java
-------------------------------------------------
package com.pandy.ssh4.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pandy.ssh4.service.SampleService;

@Controller
public class TestController {

	@Resource(name = "sampleService")
	public SampleService sampleService;

	@RequestMapping(value = "/doTest.do")
	public String doTest() {
		// testService.listAll();

		sampleService.sample1();
		sampleService.sample3();
		sampleService.doEhcache();
		return "success";
	}

}




src/main/webapp/index.jsp
--------------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试首页</title>
</head>
<body>
	<center><h1>首页</h1></center>
	<a href="doTest.do">go test</a>
</body>
</html>



src/main/webapp/views/success.jsp
---------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试首页</title>
</head>
<body>
	<center><h1>成功</h1></center>
</body>
</html>



src/main/webapp/views/failure.jsp
--------------------------------------------
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试首页</title>
</head>
<body>
	<center><h1>失败</h1></center>
</body>
</html> 
  
   
   
   
   
    http://localhost:8080/JBPM5sh/doTest.do
    -----------------------------------------------OUTPUT
12:47:13,628  INFO sqlonly:236 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy', NULL)
12:47:13,630  INFO sqltiming:357 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy', NULL)  {executed in 0 msec}
12:47:13,638  WARN JdbcCoordinatorImpl:411 - HHH000387: ResultSet's statement was not registered
----------------------------------------增加完成
12:47:13,887  INFO sqlonly:236 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,888  INFO sqltiming:357 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
Table3 [id=13, name=pandy, password=null, email=panyongzheng@163.com]
验证完成
----------------------------------------修改完成
12:47:13,917  INFO sqlonly:236 - update TABLE3 set EMAIL='panyongzheng@163.com', NAME='New Name', PASSWORD=NULL where ID=13

12:47:13,918  INFO sqltiming:357 - update TABLE3 set EMAIL='panyongzheng@163.com', NAME='New Name', PASSWORD=NULL where ID=13
{executed in 1 msec}
12:47:13,920  INFO sqlonly:236 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,921  INFO sqltiming:357 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
Table3 [id=13, name=New Name, password=null, email=panyongzheng@163.com]
验证完成
----------------------------------------删除完成 id=13
12:47:13,924  INFO sqlonly:236 - delete from TABLE3 where ID=13
12:47:13,925  INFO sqltiming:357 - delete from TABLE3 where ID=13  {executed in 0 msec}
12:47:13,926  INFO sqlonly:236 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:13,927  INFO sqltiming:357 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
验证完成
----------------------------------------增加两个记录来测试缓存
12:47:14,021  INFO sqlonly:236 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy1', NULL)

12:47:14,022  INFO sqltiming:357 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy1', NULL)
{executed in 0 msec}
12:47:14,023  WARN JdbcCoordinatorImpl:411 - HHH000387: ResultSet's statement was not registered
12:47:14,024  INFO sqlonly:236 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy2', NULL)

12:47:14,025  INFO sqltiming:357 - insert into TABLE3 (EMAIL, NAME, PASSWORD) values ('panyongzheng@163.com', 'pandy2', NULL)
{executed in 0 msec}
12:47:14,026  WARN JdbcCoordinatorImpl:411 - HHH000387: ResultSet's statement was not registered
----------------------------------------增加两个记录信息
12:47:14,028  INFO sqlonly:236 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:14,029  INFO sqltiming:357 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}
listAll-> Table3 [id=14, name=pandy1, password=null, email=panyongzheng@163.com]
listAll-> Table3 [id=15, name=pandy2, password=null, email=panyongzheng@163.com]
---------------第一次查询--------------------
12:47:14,103  INFO sqlonly:236 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_
12:47:14,104  INFO sqltiming:357 - select table3x0_.ID as ID1_0_, table3x0_.EMAIL as EMAIL2_0_, table3x0_.NAME as NAME3_0_, table3x0_.PASSWORD
as PASSWORD4_0_ from TABLE3 table3x0_  {executed in 1 msec}

2
---------------第二次查询--------------------
2
---------------缓存信息--------------------
Statistics[start time=1368852423495,sessions opened=3,sessions closed=2,transactions=2,successful transactions=2,optimistic lock failures=0,flushes=3,connections obtained=3,statements prepared=10,statements closed=0,second level cache puts=2,second level cache hits=0,second level cache misses=0,entities loaded=2,entities updated=1,entities inserted=3,entities deleted=1,entities fetched=0,collections loaded=0,collections updated=0,collections removed=0,collections recreated=0,collections fetched=0,naturalId queries executed to database=0,naturalId cache puts=0,naturalId cache hits=0,naturalId cache misses=0,naturalId max query time=0,queries executed to database=5,query cache puts=1,query cache hits=1,query cache misses=1,update timestamps cache puts=7,update timestamps cache hits=1,update timestamps cache misses=0,max query time=12]
put:2
hit:0
miss:0


注意到第二次查询。不再查询数据库,就是缓存了。
分享到:
评论
2 楼 pyzheng 2013-09-30  
vip_wst 写道
我去 没有附近的啊


什么意思  没有附件?有pom.xml还没足够么?
1 楼 vip_wst 2013-09-30  
我去 没有附近的啊

相关推荐

Global site tag (gtag.js) - Google Analytics