Skip to content

Commit

Permalink
Fixed build issues with JPA API 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored and lukasj committed Sep 20, 2023
1 parent 1f2fc14 commit 82ffef8
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 1,002 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,61 +300,30 @@ public EJBQueryImpl setLockMode(LockModeType lockMode) {
return (EJBQueryImpl) super.setLockMode(lockMode);
}

/**
* The cache retrieval mode that will be in effect during query execution.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public CacheRetrieveMode getCacheRetrieveMode() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Set the cache retrieval mode that is in effect during query execution.
* This cache retrieval mode overrides the cache retrieve mode in use by the entity manager.
*
* @param cacheRetrieveMode cache retrieval mode
* @return the same query instance
* @since 4.1
*/
// TODO-API-3.2
@Override
public TypedQuery<X> setCacheRetrieveMode(CacheRetrieveMode cacheRetrieveMode) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* The cache storage mode that will be in effect during query execution.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public CacheStoreMode getCacheStoreMode() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* Set the cache storage mode that is in effect during query execution.
* This cache storage mode overrides the cache storage mode in use by the entity manager.
*
* @param cacheStoreMode cache storage mode
* @return the same query instance
* @since 4.1
*/
// TODO-API-3.2
@Override
public TypedQuery<X> setCacheStoreMode(CacheStoreMode cacheStoreMode) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

/**
* The query timeout.
*
* @since 4.1
*/
// TODO-API-3.2
@Override
public Integer getTimeout() {
Expand Down Expand Up @@ -478,7 +447,7 @@ public X getSingleResult() {
}

// TODO-API-3.2
//@Override
@Override
public X getSingleResultOrNull() {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public <T> Subgraph<? extends T> addSubclassSubgraph(Class<? extends T> type) {
return addTreatedSubgraph((Class)type);
}

// TODO-API-3.2: alias pro addSubgraph se st. attr
// TODO-API-3.2
@Override
public <Y> Subgraph<Y> addTreatedSubgraph(Attribute<? super X, ? super Y> attribute, Class<Y> type) {
return addSubgraph(attribute.getName(), type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.PersistenceUnitTransactionType;
import jakarta.persistence.PersistenceUnitUtil;
import jakarta.persistence.Query;
import jakarta.persistence.SchemaManager;
Expand Down Expand Up @@ -554,13 +555,16 @@ public PersistenceUnitUtil getPersistenceUnitUtil() {
return this;
}

/**
* Return interface providing access to schema management operations for the persistence unit.
*
* @return <code>SchemaManager</code> interface
* @throws IllegalStateException if the entity manager factory has been closed
* @since 4.1
*/
// TODO-API-3.2 - SEPersistenceUnitInfo must return new PersistenceUnitTransactionType instead of old spi
@Override
public PersistenceUnitTransactionType getTransactionType() {
// Temporary mapping between old and new PersistenceUnitTransactionType
return switch (setupImpl.getPersistenceUnitInfo().getTransactionType()) {
case JTA -> PersistenceUnitTransactionType.JTA;
case RESOURCE_LOCAL -> PersistenceUnitTransactionType.RESOURCE_LOCAL;
};
}

// TODO-API-3.2
@Override
public SchemaManager getSchemaManager() {
Expand Down Expand Up @@ -739,7 +743,7 @@ public boolean isLoaded(Object entity, String attributeName) {
}

// TODO-API-3.2
//@Override
@Override
public <E> boolean isLoaded(E e, Attribute<? super E, ?> attribute) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}
Expand All @@ -766,32 +770,32 @@ public boolean isLoaded(Object entity) {
}

// TODO-API-3.2
//@Override
public void load(Object o, String s) {
@Override
public void load(Object entity, String attributeName) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

// TODO-API-3.2
//@Override
public <E> void load(E e, Attribute<? super E, ?> attribute) {
@Override
public <E> void load(E entity, Attribute<? super E, ?> attribute) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

// TODO-API-3.2
//@Override
public void load(Object o) {
@Override
public void load(Object entity) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

// TODO-API-3.2
//@Override
public boolean isInstance(Object o, Class<?> aClass) {
@Override
public boolean isInstance(Object entity, Class<?> entityClass) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

// TODO-API-3.2
//@Override
public <T> Class<? extends T> getClass(T t) {
@Override
public <T> Class<? extends T> getClass(T entity) {
throw new UnsupportedOperationException("Jakarta Persistence 3.2 API was not implemented yet");
}

Expand All @@ -815,16 +819,6 @@ public Object getIdentifier(Object entity) {
}
}

/**
* Return the version of the entity.
* A generated version is not guaranteed to be available until after the database insert has occurred.
* Returns null if the entity does not yet have an id.
*
* @param entity entity instance
* @return id of the entity
* @throws IllegalArgumentException if the object is found not to be an entity
* @since 4.1
*/
// TODO-API-3.2
@Override
public Object getVersion(Object entity) {
Expand Down Expand Up @@ -887,35 +881,11 @@ public <T> void addNamedEntityGraph(String graphName, EntityGraph<T> entityGraph
this.getAbstractSession().getDescriptor(((EntityGraphImpl)entityGraph).getClassType()).addAttributeGroup(group);
}

/**
* Create a new application-managed {@code EntityManager} with an active
* transaction, and execute the given function, passing the {@code EntityManager}
* to the function.
* <p>
* If the transaction type of the persistence unit is JTA, and there is a JTA
* transaction already associated with the caller, then the {@code EntityManager}
* is associated with this current transaction. If the given function throws an
* exception, the JTA transaction is marked for rollback, and the exception is
* rethrown.
* <p>
* Otherwise, if the transaction type of the persistence unit is resource-local,
* or if there is no JTA transaction already associated with the caller, then
* the {@code EntityManager} is associated with a new transaction. If the given
* function returns without throwing an exception, this transaction is committed.
* If the function does throw an exception, the transaction is rolled back, and
* the exception is rethrown.
* <p>
* Finally, the {@code EntityManager} is closed before this method returns
* control to the client.
*
* @param work a function to be executed in the scope of the transaction
* @since 4.1
*/
// TODO-API-3.2
@Override
public void runInTransaction(Consumer<EntityManager> work) {
try (EntityManager em = createEntityManager()) {
switch (setupImpl.getPersistenceUnitInfo().getTransactionType()) {
switch (getTransactionType()) {
case JTA:
em.joinTransaction();
work.accept(em);
Expand All @@ -939,37 +909,11 @@ public void runInTransaction(Consumer<EntityManager> work) {
}
}

/**
* Create a new application-managed {@code EntityManager} with an active
* transaction, and call the given function, passing the {@code EntityManager}
* to the function.
* <p>
* If the transaction type of the persistence unit is JTA, and there is a JTA
* transaction already associated with the caller, then the {@code EntityManager}
* is associated with this current transaction. If the given function returns
* without throwing an exception, the result of the function is returned. If the
* given function throws an exception, the JTA transaction is marked for rollback,
* and the exception is rethrown.
* <p>
* Otherwise, if the transaction type of the persistence unit is resource-local,
* or if there is no JTA transaction already associated with the caller, then
* the {@code EntityManager} is associated with a new transaction. If the given
* function returns without throwing an exception, this transaction is committed
* and the result of the function is returned. If the function does throw an
* exception, the transaction is rolled back, and the exception is rethrown.
* <p>
* Finally, the {@code EntityManager} is closed before this method returns
* control to the client.
*
* @param work a function to be called in the scope of the transaction
* @return the value returned by the given function
* @since 4.1
*/
// TODO-API-3.2
@Override
public <R> R callInTransaction(Function<EntityManager, R> work) {
try (EntityManager em = createEntityManager()) {
switch (setupImpl.getPersistenceUnitInfo().getTransactionType()) {
switch (getTransactionType()) {
case JTA:
em.joinTransaction();
return work.apply(em);
Expand Down

0 comments on commit 82ffef8

Please sign in to comment.