Skip to content

Commit

Permalink
Upgrade undertow, add WeldInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
13959261122 authored and 13959261122 committed Aug 19, 2022
1 parent 0b653b6 commit 9dea2e5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions corant-boms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<version.grpc>1.40.1</version.grpc>
<version.hanlp>portable-1.7.8</version.hanlp>
<version.hibernate-ogm-core>5.4.1.Final</version.hibernate-ogm-core>
<version.hibernate-orm-core>5.3.27.Final</version.hibernate-orm-core>
<version.hibernate-orm-core>5.3.28.Final</version.hibernate-orm-core>
<version.hibernate-validator-cdi>6.0.16.Final</version.hibernate-validator-cdi>
<version.hikariCP>3.4.5</version.hikariCP>
<version.hppc>0.9.1</version.hppc>
Expand Down Expand Up @@ -170,7 +170,7 @@
<version.swagger>2.1.12</version.swagger>
<version.swagger-ui-webjars>4.10.3</version.swagger-ui-webjars>
<version.testng>6.9.9</version.testng>
<version.undertow>2.2.18.Final</version.undertow>
<version.undertow>2.2.19.Final</version.undertow>
<version.vertx>4.1.4</version.vertx>
<version.weld-junit4>2.0.2.Final</version.weld-junit4>
<version.weld-junit5>2.0.2.Final</version.weld-junit5>
Expand Down
12 changes: 12 additions & 0 deletions corant-context/src/main/java/org/corant/context/Contexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.util.TypeLiteral;
import org.corant.config.Configs;
import org.jboss.weld.context.BoundContext;
import org.jboss.weld.context.WeldAlterableContext;
Expand All @@ -37,6 +39,7 @@
import org.jboss.weld.context.bound.BoundRequestContext;
import org.jboss.weld.context.bound.BoundSessionContext;
import org.jboss.weld.context.bound.MutableBoundRequest;
import org.jboss.weld.inject.WeldInstance;
import org.jboss.weld.manager.api.WeldManager;

/**
Expand All @@ -52,6 +55,15 @@ public class Contexts {
static final boolean propagateStrictly =
Configs.getValue("corant.context.propagate.strictly", Boolean.class, Boolean.FALSE);

/**
* Returns an enhanced version of of {@link Instance} provide by Weld.
*/
public static WeldInstance<Object> getWeldInstance() {
return Beans.resolve(new TypeLiteral<WeldInstance<Object>>() {
private static final long serialVersionUID = 1235213990342343584L;
});
}

/**
* Returns whether there is an active context for all given scope types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
package org.corant.modules.ddd.shared.repository;

import static org.corant.shared.util.Objects.defaultObject;
import static org.corant.shared.util.Objects.forceCast;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -25,10 +27,13 @@
import javax.persistence.LockModeType;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaQuery;
import org.corant.context.Contexts;
import org.corant.context.qualifier.AutoCreated;
import org.corant.modules.ddd.Entity;
import org.corant.modules.ddd.TypedRepository;
import org.corant.modules.jpa.shared.JPAQueries;
import org.corant.modules.jpa.shared.JPAQueries.TypedJPAQuery;
import org.jboss.weld.util.reflection.ParameterizedTypeImpl;

/**
* corant-modules-ddd-shared
Expand All @@ -38,6 +43,28 @@
*/
public interface TypedJPARepository<T extends Entity> extends TypedRepository<T, Query> {

/**
* Returns a typed JPA repository, the underling processing depend on CDI & Weld. If qualifiers
* are not assigned, return a auto created instance.
*
* @param <T> the entity type to be used in the repository
* @param entityClass the entity type to be used in the repository
* @return an auto created Typed JPA repository
*/
public static <T extends Entity> TypedJPARepository<T> instance(Class<T> entityClass,
Annotation... qualifiers) {
if (qualifiers.length == 0) {
return forceCast(Contexts.getWeldInstance()
.select(new ParameterizedTypeImpl(TypedJPARepository.class, entityClass),
AutoCreated.INST)
.get());
} else {
return forceCast(Contexts.getWeldInstance()
.select(new ParameterizedTypeImpl(TypedJPARepository.class, entityClass), qualifiers)
.get());
}
}

/**
* {@link EntityManager#clear()}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ static TransactionalActuator actuator() {
return new TransactionalActuator();
}

/**
* @see #actuator()
*/
static TransactionalActuator withTransaction() {
return new TransactionalActuator();
}

/**
* Get current transaction or null if current has not transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
public class IterablesTest extends TestCase {

@SuppressWarnings("deprecation")
@Test
public void test() {
Iterable<String> it1 = listOf("1", "2");
Expand Down

0 comments on commit 9dea2e5

Please sign in to comment.