| Summary: | Enhanced EntityManagerImpl.unwrap to include additional session types | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Doug Clarke <douglas.clarke> |
| Component: | Eclipselink | Assignee: | Doug Clarke <douglas.clarke> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | andrei.ilitchev, gordon.yorke, peter.krogh |
| Version: | unspecified | Flags: | gordon.yorke:
review+
|
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 244124 | ||
I am making this a blocker for 244124 (nested fetchgroup & LoadGroup) work since the suggested JpaHelper.load method will use this unwrap method to access the requires AbstractSession. public <T> T unwrap(Class<T> cls) {
try {
if (cls.equals(UnitOfWork.class) || cls.equals(UnitOfWorkImpl.class) || cls.equals(RepeatableWriteUnitOfWork.class)) {
return (T) this.getUnitOfWork();
} else if (cls.equals(JpaEntityManager.class)) {
return (T) this;
} else if (cls.equals(Session.class) || cls.equals(Server.class) || cls.equals(ServerSession.class) || cls.equals(AbstractSession.class)) {
return (T) this.getServerSession();
} else if (cls.equals(java.sql.Connection.class)) {
UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) this.getUnitOfWork();
if (!unitOfWork.isInTransaction()) {
unitOfWork.beginEarlyTransaction();
return (T) unitOfWork.getAccessor().getConnection();
}
}
throw new PersistenceException(ExceptionLocalization.buildMessage("Provider-does-not-support-the-call", null));
} catch (RuntimeException e) {
throw e;
}
}
Cheched into trunk. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
The unwrap method should be enhanced to support some additional internal session types to expand the usability of this method in combination with native API calls. these sessions include: - UnitOfWorkImpl - ServerSession - Server (interface) - AbstractSession The proposed method would look like: public <T> T unwrap(Class<T> cls) { try { if (cls.equals(UnitOfWork.class) || cls.equals(UnitOfWorkImpl.class)) { return (T) this.getUnitOfWork(); } else if (cls.equals(JpaEntityManager.class)) { return (T) this; } else if (cls.equals(Session.class) || cls.equals(Server.class) || cls.equals(ServerSession.class) || cls.equals(AbstractSession.class)) { return (T) this.getServerSession(); } else if (cls.equals(java.sql.Connection.class)) { UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl) this.getUnitOfWork(); if (!unitOfWork.isInTransaction()) { unitOfWork.beginEarlyTransaction(); return (T) unitOfWork.getAccessor().getConnection(); } } throw new PersistenceException(ExceptionLocalization.buildMessage("Provider-does-not-support-the-call", null)); } catch (RuntimeException e) { throw e; } }