All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.testing.jdbc.SQLStatementInterceptor Maven / Gradle / Ivy

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.testing.jdbc;

import java.util.LinkedList;

import org.hibernate.resource.jdbc.spi.StatementInspector;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * todo (6.0) : use ManagedBean to locate SQLStatementInterceptor if specified by Class
 *
 * @author Vlad Mihalcea
 */
public class SQLStatementInterceptor implements StatementInspector {

	private final LinkedList sqlQueries = new LinkedList<>();

	public LinkedList getSqlQueries() {
		return sqlQueries;
	}

	public void clear() {
		sqlQueries.clear();
	}

	public void assertExecuted(String expected) {
		assertTrue(sqlQueries.contains( expected ));
	}

	public void assertExecutedCount(int expected) {
		assertEquals(expected, sqlQueries.size());
	}

	@Override
	public String inspect(String sql) {
		sqlQueries.add( sql );
		return sql;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy