mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Add test
This commit is contained in:
parent
f9f81fb49b
commit
daa246c4db
@ -175,8 +175,6 @@ public abstract class AbstractSQLQuery<T, Q extends AbstractSQLQuery<T, Q>> exte
|
||||
listeners.end(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the results as an JDBC result set
|
||||
*
|
||||
|
||||
@ -21,7 +21,11 @@ import com.querydsl.core.QueryException;
|
||||
/**
|
||||
* {@code SQLCloseListener} closes the JDBC connection at the end of the query or clause execution
|
||||
*/
|
||||
public class SQLCloseListener extends SQLBaseListener {
|
||||
public final class SQLCloseListener extends SQLBaseListener {
|
||||
|
||||
public static final SQLCloseListener DEFAULT = new SQLCloseListener();
|
||||
|
||||
private SQLCloseListener() { }
|
||||
|
||||
@Override
|
||||
public void end(SQLListenerContext context) {
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
package com.querydsl.sql;
|
||||
|
||||
import static com.querydsl.sql.Constants.employee;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.commons.lang.CloseableIterator;
|
||||
import com.querydsl.sql.domain.Employee;
|
||||
|
||||
public class SQLCloseListenerTest {
|
||||
|
||||
private SQLQuery<Employee> query;
|
||||
|
||||
@Before
|
||||
public void setUp() throws SQLException, ClassNotFoundException {
|
||||
Connections.initH2();
|
||||
Configuration conf = new Configuration(H2Templates.DEFAULT);
|
||||
conf.addListener(SQLCloseListener.DEFAULT);
|
||||
query = new SQLQuery<Void>(Connections.getConnection(), conf).select(employee).from(employee);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
Connections.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch() {
|
||||
assertFalse(query.fetch().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchOne() {
|
||||
assertNotNull(query.limit(1).fetchOne());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchFirst() {
|
||||
assertNotNull(query.fetchFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchResults() {
|
||||
assertNotNull(query.fetchResults());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iterate() {
|
||||
CloseableIterator<Employee> it = query.iterate();
|
||||
try {
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
}
|
||||
} finally {
|
||||
it.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user