Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-10669 - Allow to add SF-scoped services through a ServiceContributor
- Loading branch information
Showing
8 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...rc/main/java/org/hibernate/service/internal/SessionFactoryServiceRegistryBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.service.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.boot.spi.SessionFactoryOptions; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.service.Service; | ||
import org.hibernate.service.spi.ServiceRegistryImplementor; | ||
import org.hibernate.service.spi.SessionFactoryServiceInitiator; | ||
import org.hibernate.service.spi.SessionFactoryServiceRegistry; | ||
import org.hibernate.service.spi.SessionFactoryServiceRegistryBuilder; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class SessionFactoryServiceRegistryBuilderImpl implements SessionFactoryServiceRegistryBuilder { | ||
private final ServiceRegistryImplementor parent; | ||
|
||
private final List<SessionFactoryServiceInitiator> initiators = standardInitiatorList(); | ||
private final List<ProvidedService> providedServices = new ArrayList<>(); | ||
|
||
public SessionFactoryServiceRegistryBuilderImpl(ServiceRegistryImplementor parent) { | ||
this.parent = parent; | ||
} | ||
|
||
/** | ||
* Used from the {@link #initiators} variable initializer | ||
* | ||
* @return List of standard initiators | ||
*/ | ||
private static List<SessionFactoryServiceInitiator> standardInitiatorList() { | ||
final List<SessionFactoryServiceInitiator> initiators = new ArrayList<>(); | ||
initiators.addAll( StandardSessionFactoryServiceInitiators.LIST ); | ||
return initiators; | ||
} | ||
|
||
/** | ||
* Adds a service initiator. | ||
* | ||
* @param initiator The initiator to be added | ||
* | ||
* @return this, for method chaining | ||
*/ | ||
@Override | ||
@SuppressWarnings( {"UnusedDeclaration"}) | ||
public SessionFactoryServiceRegistryBuilder addInitiator(SessionFactoryServiceInitiator initiator) { | ||
initiators.add( initiator ); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a user-provided service. | ||
* | ||
* @param serviceRole The role of the service being added | ||
* @param service The service implementation | ||
* | ||
* @return this, for method chaining | ||
*/ | ||
@Override | ||
@SuppressWarnings( {"unchecked"}) | ||
public SessionFactoryServiceRegistryBuilder addService(final Class serviceRole, final Service service) { | ||
providedServices.add( new ProvidedService( serviceRole, service ) ); | ||
return this; | ||
} | ||
|
||
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry( | ||
SessionFactoryImplementor sessionFactory, | ||
SessionFactoryOptions options) { | ||
return new SessionFactoryServiceRegistryImpl( | ||
parent, | ||
initiators, | ||
providedServices, | ||
sessionFactory, | ||
options | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
hibernate-core/src/main/java/org/hibernate/service/spi/SessionFactoryServiceContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.service.spi; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public interface SessionFactoryServiceContributor { | ||
/** | ||
* Contribute services to the indicated registry builder. | ||
* | ||
* @param serviceRegistryBuilder The builder to which services (or initiators) should be contributed. | ||
*/ | ||
void contribute(SessionFactoryServiceRegistryBuilder serviceRegistryBuilder); | ||
} |
19 changes: 19 additions & 0 deletions
19
...te-core/src/main/java/org/hibernate/service/spi/SessionFactoryServiceRegistryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.service.spi; | ||
|
||
import org.hibernate.service.Service; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public interface SessionFactoryServiceRegistryBuilder { | ||
SessionFactoryServiceRegistryBuilder addInitiator(SessionFactoryServiceInitiator initiator); | ||
|
||
@SuppressWarnings( {"unchecked"}) | ||
SessionFactoryServiceRegistryBuilder addService(Class serviceRole, Service service); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters