mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Merge pull request #897 from querydsl/listener-changes
Small listener usage changes
This commit is contained in:
commit
c558616126
@ -13,6 +13,7 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@ -22,26 +23,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mysema.commons.lang.CloseableIterator;
|
||||
import com.mysema.query.*;
|
||||
import com.mysema.query.support.QueryMixin;
|
||||
import com.mysema.query.types.*;
|
||||
import com.mysema.util.ResultSetAdapter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mysema.commons.lang.CloseableIterator;
|
||||
import com.mysema.query.DefaultQueryMetadata;
|
||||
import com.mysema.query.QueryException;
|
||||
import com.mysema.query.QueryFlag;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.QueryModifiers;
|
||||
import com.mysema.query.SearchResults;
|
||||
import com.mysema.query.support.QueryMixin;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.FactoryExpression;
|
||||
import com.mysema.query.types.ParamExpression;
|
||||
import com.mysema.query.types.ParamNotSetException;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.util.ResultSetAdapter;
|
||||
|
||||
/**
|
||||
* AbstractSQLQuery is the base type for SQL query implementations
|
||||
*
|
||||
@ -140,12 +129,10 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
*
|
||||
* @param context the current context in play
|
||||
* @param e the exception
|
||||
* @return the new context
|
||||
*/
|
||||
protected SQLListenerContextImpl onException(SQLListenerContextImpl context, Exception e) {
|
||||
protected void onException(SQLListenerContextImpl context, Exception e) {
|
||||
context.setException(e);
|
||||
listeners.exception(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,7 +191,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
}
|
||||
};
|
||||
} catch (SQLException e) {
|
||||
context = onException(context, e);
|
||||
onException(context, e);
|
||||
throw configuration.translate(queryString, constants, e);
|
||||
} finally {
|
||||
reset();
|
||||
@ -224,7 +211,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <RT> CloseableIterator<RT> iterateSingle(QueryMetadata metadata, @Nullable final Expression<RT> expr) {
|
||||
SQLListenerContextImpl context = startContext(conn,queryMixin.getMetadata());
|
||||
SQLListenerContextImpl context = startContext(conn, queryMixin.getMetadata());
|
||||
|
||||
listeners.preRender(context);
|
||||
SQLSerializer serializer = serialize(false);
|
||||
@ -284,8 +271,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
context = onException(context, e);
|
||||
|
||||
onException(context, e);
|
||||
throw configuration.translate(queryString, constants, e);
|
||||
} finally {
|
||||
endContext(context);
|
||||
@ -374,8 +360,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
stmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
context = onException(context, e);
|
||||
|
||||
onException(context, e);
|
||||
throw configuration.translate(queryString, constants, e);
|
||||
} finally {
|
||||
endContext(context);
|
||||
@ -471,7 +456,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
}
|
||||
|
||||
private long unsafeCount() throws SQLException {
|
||||
SQLListenerContextImpl context = startContext(conn,getMetadata());
|
||||
SQLListenerContextImpl context = startContext(conn, getMetadata());
|
||||
|
||||
listeners.preRender(context);
|
||||
SQLSerializer serializer = serialize(true);
|
||||
@ -501,8 +486,7 @@ public abstract class AbstractSQLQuery<Q extends AbstractSQLQuery<Q>> extends Pr
|
||||
|
||||
return rs.getLong(1);
|
||||
} catch (SQLException e) {
|
||||
context = onException(context, e);
|
||||
|
||||
onException(context, e);
|
||||
throw configuration.translate(queryString, constants, e);
|
||||
} finally {
|
||||
try {
|
||||
|
||||
@ -452,7 +452,7 @@ public final class Configuration {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listeners
|
||||
* @param listener
|
||||
*/
|
||||
public void addListener(SQLListener listener) {
|
||||
listeners.add(listener);
|
||||
|
||||
@ -13,6 +13,9 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mysema.commons.lang.Pair;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
@ -23,9 +26,6 @@ import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.SubQueryExpression;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SQLListeners is an SQLListener implementation which dispatches the
|
||||
* notifications to a list of SQLListener instances
|
||||
@ -35,9 +35,9 @@ import java.util.List;
|
||||
public class SQLListeners implements SQLDetailedListener {
|
||||
|
||||
@Nullable
|
||||
private final SQLListenerAdapter parent;
|
||||
private final SQLDetailedListener parent;
|
||||
|
||||
private final List<SQLListenerAdapter> listeners = Lists.newArrayList();
|
||||
private final List<SQLDetailedListener> listeners = Lists.newArrayList();
|
||||
|
||||
public SQLListeners(SQLListener parent) {
|
||||
this.parent = new SQLListenerAdapter(parent);
|
||||
@ -151,7 +151,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.start(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.start(context);
|
||||
}
|
||||
}
|
||||
@ -161,7 +161,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.preRender(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.preRender(context);
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.rendered(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.rendered(context);
|
||||
}
|
||||
}
|
||||
@ -181,7 +181,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.prePrepare(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.prePrepare(context);
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.prepared(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.prepared(context);
|
||||
}
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.preExecute(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.preExecute(context);
|
||||
}
|
||||
}
|
||||
@ -211,7 +211,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.executed(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.executed(context);
|
||||
}
|
||||
}
|
||||
@ -221,7 +221,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.end(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.end(context);
|
||||
}
|
||||
}
|
||||
@ -231,7 +231,7 @@ public class SQLListeners implements SQLDetailedListener {
|
||||
if (parent != null) {
|
||||
parent.exception(context);
|
||||
}
|
||||
for (SQLListenerAdapter listener : listeners) {
|
||||
for (SQLDetailedListener listener : listeners) {
|
||||
listener.exception(context);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user