Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions api/src/main/java/jakarta/data/repository/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,21 @@
@Target(ElementType.TYPE)
public @interface Repository {
/**
* Value for the {@link Repository#provider()} attribute that allows the use
* of any available Jakarta Data provider that supports the type of entity
* annotation that is present on the repository's entity class.
* Value for the {@link #provider()} attribute that allows the use of
* any available Jakarta Data provider that supports the type of entity
* annotation that is present on the repository's entity classes.
*/
String ANY_PROVIDER = "";

/**
* <p>Value for the {@link Repository#dataStore()} attribute that indicates
* to use
* <p>Value for the {@link #dataStore()} attribute that indicates use of
* a default data store.</p>
*
* <p>When running in a Jakarta EE profile or platform and the entity
* annotations
* indicate a relational database, the default data store is the Jakarta EE
* default data source, {@code java:comp/DefaultDataSource}. Otherwise, the
* default data store is determined by the Jakarta Data provider.</p>
* <p>In a Jakarta EE profile or platform environment, if the repository
* requires a {@code javax.sql.DataSource}, the default data store is the
* Jakarta EE default data source with name
* {@code java:comp/DefaultDataSource}. Otherwise, the default data store
* is determined by the Jakarta Data provider.</p>
*
* <p>The default data store might require additional vendor-specific
* configuration, depending on the vendor.</p>
Expand All @@ -100,14 +99,23 @@
* Interoperability with Jakarta Config is reserved for future versions
* of Jakarta Data.
* </li>
* <li>If running in a Jakarta EE profile or platform and the entity annotations
* indicate a relational database and the value begins with {@code java:} and
* matches the name of a {@code jakarta.annotation.sql.DataSourceDefinition},
* the JNDI name of a data source, or a resource reference to a data source,
* then the corresponding {@code javax.sql.DataSource} is used as the data store.
* If the same conditions are met but the value matches a persistence unit
* reference, then the corresponding {@code jakarta.persistence.PersistenceUnit}
* is used as the data store.
* <li>In a Jakarta EE profile or platform environment, if the repository
* implementation requires a {@code javax.sql.DataSource}, and if the
* value begins with {@code java:} and matches the name of a
* {@code jakarta.annotation.sql.DataSourceDefinition}, the JNDI name of
* a {@code DataSource}, or a resource reference to a {@code DataSource},
* then the corresponding {@code DataSource} obtained from JNDI is used.
* </li>
* <li>In a Jakarta EE profile or platform environment, if the repository
* implementation requires a Jakarta Persistence
* {@code jakarta.persistence.EntityManagerFactory} and if the value does
* not begin with {@code java:} and matches the name of a persistence unit,
* then the container-managed {@code EntityManagerFactory} for that
* persistence unit is used, obtained as if it had been injected using the
* {@code PersistenceUnit} annotation. Or, if the value does begin with
* {@code java:} and matches the name of a persistence unit reference,
* then the corresponding {@code EntityManagerFactory} obtained from JNDI
* is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered why I didn't write this with the PersistenceUnit name in the first place.
I'm not aware of an API or SPI that Jakarta Persistence provides to do this given the name of a persistence unit:

     * then the container-managed {@code EntityManagerFactory} for that
     * persistence unit is used, obtained as if it had been injected using the
     * {@code PersistenceUnit} annotation.

The closest I see is Persistence.createEntityManagerFactory(persistenceUnitName), but that is only for Java SE and also not container managed. It's also possible that there is something in Jakarta Persistence that I am overlooking.

I would also be fine with including some language for Java SE usage here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PersistenceContext and @PersistenceUnit both inject based on the unit name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the Javadoc is super-confusing:

    /**
     * (Optional) The name of the persistence unit as defined
     * in the {@code persistence.xml} file. If specified, the
     * persistence unit for the entity manager factory that is
     * accessible in JNDI must have the same name.
     */

I don't know what that second sentence means. But I'm basing my assertion on the first sentence:

The name of the persistence unit as defined in the persistence.xml file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PersistenceContext and @PersistenceUnit both inject based on the unit name.

Right, but we have written the Data spec not to require a compile time step that generates code. I think we would need an equivalent to Persistence.createEntityManagerFactory(persistenceUnitName) for Jakarta EE usage to ensure it is always implementable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would need an equivalent to Persistence.createEntityManagerFactory(persistenceUnitName) for Jakarta EE usage to ensure it is always implementable.

+1

* </li>
* <li>Otherwise, the value serves as an identifier linking to vendor-specific
* configuration for the Jakarta Data provider to interpret in a vendor-specific
Expand Down