-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support fror @Inject StatelessSession
Why: * Sometimes you just want to do raw data access This change addreses the need by: * Add StatelessSession as a possible injection.
- Loading branch information
1 parent
6167fae
commit 66806d5
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
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
49 changes: 49 additions & 0 deletions
49
...hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/StatelessSessionTest.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,49 @@ | ||
package io.quarkus.hibernate.orm; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.TransactionRequiredException; | ||
|
||
import org.hibernate.StatelessSession; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.hibernate.orm.enhancer.Address; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* @author Max Rydahl Andersen <manderse@redhat.com> | ||
*/ | ||
public class StatelessSessionTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(Address.class) | ||
.addAsResource("application.properties")); | ||
|
||
@Inject | ||
StatelessSession statelessSession; | ||
|
||
@Test | ||
public void testStatelessSession() { | ||
Arc.container().requestContext().activate(); | ||
try { | ||
List list = statelessSession.createNativeQuery("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS") | ||
.addScalar("VALUE") | ||
.list(); | ||
assertNotNull(list); | ||
} finally { | ||
Arc.container().requestContext().terminate(); | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...ntime/src/main/java/io/quarkus/hibernate/orm/runtime/DefaultStatelessSessionProducer.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,16 @@ | ||
package io.quarkus.hibernate.orm.runtime; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
import javax.persistence.PersistenceContext; | ||
|
||
import org.hibernate.StatelessSession; | ||
|
||
public class DefaultStatelessSessionProducer { | ||
|
||
@Produces | ||
@PersistenceContext | ||
@Singleton | ||
StatelessSession statelessSession; | ||
|
||
} |
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