Community
Participate
Working Groups
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; } }
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