use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.
the class PersistenceContextAnnotationProcessor method buildProvider.
@Override
public MinijaxProvider<EntityManager> buildProvider(final MinijaxInjectorState state, final Class<EntityManager> type, final Annotation[] annotations) {
final PersistenceContext persistenceContext = getPersistenceContextAnnotation(annotations);
final EntityManagerFactory emf = factories.get(persistenceContext.name());
if (emf == null) {
throw new InjectionException("Persistence context \"" + persistenceContext.name() + "\" not found");
}
return new EntityManagerProvider(emf);
}
use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.
the class ConstructorProvider method get.
@Override
public T get(final Object context) {
try {
final T result = ctor.newInstance(getParams(paramProviders, context));
initImpl(result, context);
return result;
} catch (final InvocationTargetException ex) {
final Throwable inner = ex.getCause();
throw new InjectionException(inner.getMessage(), inner);
} catch (final Exception e) {
throw new InjectionException(String.format("Can't instantiate %s", ctor), e);
}
}
use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.
the class EntityProvider method get.
@SuppressWarnings("unchecked")
@Override
public T get(final Object obj) {
final MinijaxRequestContext context = (MinijaxRequestContext) obj;
// If you call getInputStream -- even if you don't read from it -- the input stream is moved.
if (entityClass == MultivaluedMap.class) {
return (T) context.getForm().asForm().asMap();
}
final InputStream entityStream = context.getEntityStream();
try {
return EntityUtils.readEntity(entityClass, genericType, annotations, mediaType, context, entityStream);
} catch (final IOException ex) {
throw new InjectionException(ex.getMessage(), ex);
}
}
use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.
the class MinijaxInjector method buildProvider.
@SuppressWarnings("unchecked")
private <T> MinijaxProvider<T> buildProvider(final Key<T> key, final Set<Key<?>> chain, final Annotation[] fieldAnnotations) {
FieldAnnotationProcessor<T> processor = null;
if (fieldAnnotations != null) {
for (final Annotation fieldAnnotation : fieldAnnotations) {
final FieldAnnotationProcessor<T> p = (FieldAnnotationProcessor<T>) fieldAnnotationProcessors.get(fieldAnnotation.annotationType());
if (p != null) {
if (processor != null) {
throw new InjectionException("Conflicting field annotations");
}
processor = p;
}
}
}
if (processor == null) {
processor = new DefaultFieldAnnotationProcessor<>();
}
MinijaxProvider<T> provider = processor.buildProvider(new MinijaxInjectorState(this, key, chain), key.getType(), fieldAnnotations);
final Annotation[] typeAnnotations = key.getType().getAnnotations();
for (final Annotation typeAnnotation : typeAnnotations) {
final TypeAnnotationProcessor<T> p = (TypeAnnotationProcessor<T>) typeAnnotationProcessors.get(typeAnnotation.annotationType());
if (p != null) {
provider = p.buildProvider(provider, typeAnnotations);
}
}
return provider;
}
use of jakarta.enterprise.inject.InjectionException in project helidon by oracle.
the class CDISEPlatform method initializeExternalTransactionController.
/**
* Overrides the {@link
* ServerPlatformBase#initializeExternalTransactionController()}
* method to {@linkplain #disableJTA() disable JTA} if there is no
* {@link TransactionManager} bean present in CDI before invoking
* the {@linkplain
* ServerPlatformBase#initializeExternalTransactionController()
* superclass implementation}.
*
* <p>This method also acquires a {@link DataSource} from
* {@linkplain CDI CDI} proactively, and {@linkplain
* JNDIConnector#setDataSource(DataSource) installs it} to
* preëmpt any JNDI operations.</p>
*
* @exception ValidationException if a {@link DataSource} could
* not be acquired
*
* @see ServerPlatformBase#initializeExternalTransactionController()
*
* @see Session#getDatasourceLogin()
*
* @see DatasourceLogin#getConnector()
*
* @see JNDIConnector
*
* @see JNDIConnector#getName()
*
* @see JNDIConnector#setDataSource(DataSource)
*/
@Override
public void initializeExternalTransactionController() {
final CDI<Object> cdi = CDI.current();
assert cdi != null;
if (cdi.select(TransactionManager.class).isUnsatisfied()) {
this.disableJTA();
}
super.initializeExternalTransactionController();
// See https://github.com/oracle/helidon/issues/949. This is
// the only spot where we can actually change the Connector
// that is used by EclipseLink to look up a data source during
// JPA "SE mode" persistence unit acquisition such that it
// doesn't get overwritten by other EclipseLink internals.
final Session session = this.getDatabaseSession();
if (session != null) {
final Object login = session.getDatasourceLogin();
if (login instanceof DatasourceLogin) {
final Object connector = ((DatasourceLogin) login).getConnector();
if (connector instanceof JNDIConnector) {
final JNDIConnector jndiConnector = (JNDIConnector) connector;
final String dataSourceName = jndiConnector.getName();
if (dataSourceName != null) {
try {
jndiConnector.setDataSource(cdi.select(DataSource.class, NamedLiteral.of(dataSourceName)).get());
} catch (final InjectionException injectionExceptionOfAnyKind) {
throw ValidationException.cannotAcquireDataSource(dataSourceName, injectionExceptionOfAnyKind);
}
}
}
}
}
}
Aggregations