OPENJPA-1552 Add proper QueryImpl creation in EntityManagerImpl subclass.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@920024 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Albert Lee 2010-03-07 16:16:06 +00:00
parent b01f5718f9
commit 1c992feeb7

View File

@ -105,7 +105,7 @@ public class EntityManagerImpl
private DelegatingBroker _broker; private DelegatingBroker _broker;
private EntityManagerFactoryImpl _emf; private EntityManagerFactoryImpl _emf;
private Map<FetchConfiguration,FetchPlan> _plans = new IdentityHashMap<FetchConfiguration,FetchPlan>(1); private Map<FetchConfiguration,FetchPlan> _plans = new IdentityHashMap<FetchConfiguration,FetchPlan>(1);
private RuntimeExceptionTranslator _ret = PersistenceExceptions.getRollbackTranslator(this); protected RuntimeExceptionTranslator _ret = PersistenceExceptions.getRollbackTranslator(this);
public EntityManagerImpl() { public EntityManagerImpl() {
// for Externalizable // for Externalizable
@ -972,7 +972,7 @@ public class EntityManagerImpl
if (pq != null) { if (pq != null) {
pq.setInto(q); pq.setInto(q);
} }
return new QueryImpl(this, _ret, q).setId(qid); return newQueryImpl(q).setId(qid);
} catch (RuntimeException re) { } catch (RuntimeException re) {
throw PersistenceExceptions.toPersistenceException(re); throw PersistenceExceptions.toPersistenceException(re);
} }
@ -983,8 +983,7 @@ public class EntityManagerImpl
return createQuery((String) null); return createQuery((String) null);
assertNotCloseInvoked(); assertNotCloseInvoked();
org.apache.openjpa.kernel.Query q = ((QueryImpl) query).getDelegate(); org.apache.openjpa.kernel.Query q = ((QueryImpl) query).getDelegate();
return new QueryImpl(this, _ret, _broker.newQuery(q.getLanguage(), return newQueryImpl(_broker.newQuery(q.getLanguage(), q));
q));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1014,7 +1013,7 @@ public class EntityManagerImpl
del.compile(); del.compile();
} }
OpenJPAQuery q = new QueryImpl(this, _ret, del).setId(qid); OpenJPAQuery q = newQueryImpl(del).setId(qid);
String[] hints = meta.getHintKeys(); String[] hints = meta.getHintKeys();
Object[] values = meta.getHintValues(); Object[] values = meta.getHintValues();
for (int i = 0; i < hints.length; i++) for (int i = 0; i < hints.length; i++)
@ -1040,13 +1039,17 @@ public class EntityManagerImpl
org.apache.openjpa.kernel.Query kernelQuery = _broker.newQuery( org.apache.openjpa.kernel.Query kernelQuery = _broker.newQuery(
QueryLanguages.LANG_SQL, query); QueryLanguages.LANG_SQL, query);
kernelQuery.setResultMapping(null, mappingName); kernelQuery.setResultMapping(null, mappingName);
return new QueryImpl(this, _ret, kernelQuery); return newQueryImpl(kernelQuery);
}
protected <X> QueryImpl<X> newQueryImpl(org.apache.openjpa.kernel.Query kernelQuery) {
return new QueryImpl<X>(this, _ret, kernelQuery);
} }
/** /**
* Validate that the user provided SQL. * Validate that the user provided SQL.
*/ */
private static void validateSQL(String query) { protected void validateSQL(String query) {
if (StringUtils.trimToNull(query) == null) if (StringUtils.trimToNull(query) == null)
throw new ArgumentException(_loc.get("no-sql"), null, null, false); throw new ArgumentException(_loc.get("no-sql"), null, null, false);
} }
@ -1325,7 +1328,7 @@ public class EntityManagerImpl
* closed, it will throw its own more informative exception when we * closed, it will throw its own more informative exception when we
* delegate the pending operation to it. * delegate the pending operation to it.
*/ */
void assertNotCloseInvoked() { protected void assertNotCloseInvoked() {
if (!_broker.isClosed() && _broker.isCloseInvoked()) if (!_broker.isClosed() && _broker.isCloseInvoked())
throw new InvalidStateException(_loc.get("close-invoked"), null, throw new InvalidStateException(_loc.get("close-invoked"), null,
null, true); null, true);
@ -1562,7 +1565,7 @@ public class EntityManagerImpl
org.apache.openjpa.kernel.Query kernelQuery =_broker.newQuery(CriteriaBuilderImpl.LANG_CRITERIA, criteriaQuery); org.apache.openjpa.kernel.Query kernelQuery =_broker.newQuery(CriteriaBuilderImpl.LANG_CRITERIA, criteriaQuery);
QueryImpl<T> facadeQuery = new QueryImpl<T>(this, _ret, kernelQuery); QueryImpl<T> facadeQuery = newQueryImpl(kernelQuery);
Set<ParameterExpression<?>> params = criteriaQuery.getParameters(); Set<ParameterExpression<?>> params = criteriaQuery.getParameters();
for (ParameterExpression<?> param : params) { for (ParameterExpression<?> param : params) {