sqlinterceptortest.java

来自「好东西,hibernate-3.2.0,他是一开元的树杖hibernate-3.」· Java 代码 · 共 58 行

JAVA
58
字号
// $Id$
package org.hibernate.test.sqlinterceptor;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.test.TestCase;

/**
 * Implementation of SQLExceptionConversionTest.
 *
 * @author Steve Ebersole
 */
public class SQLInterceptorTest extends TestCase {

	public SQLInterceptorTest(String name) {
		super(name);
	}

	protected String[] getMappings() {
		return new String[] {"sqlinterceptor/User.hbm.xml"};
	}

	static class SQLInterceptor extends EmptyInterceptor {
		
		List preparedSQL = new ArrayList();
		
		public String onPrepareStatement(String sql) {
			preparedSQL.add(sql);
			return "/* sqlinterceptor */ " + sql;
		}
	}
	
	public void testSqlMutation() throws Exception {
		
		SQLInterceptor interceptor = new SQLInterceptor();
		Session session = openSession(interceptor);
		
		User user = new User();
		user.setUsername("Max");
		
		session.save(user);

		session.close();
		
		assertEquals(interceptor.preparedSQL.size(),2); // insert and identity.
	}

	public static Test suite() {
		return new TestSuite(SQLInterceptorTest.class);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?