Skip to content

Jakarta Enterprise Beans Lite implementation

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license.txt
Notifications You must be signed in to change notification settings

OmniFish-EE/omni-beans

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

omnibeans

OmniBeans intends to implement Enterprise Beans Lite using existing Jakarta EE APIs, mainly:

  • Jakarta CDI
  • Jakarta Interceptors
  • Jakarta Transactions
  • Jakarta Concurrency

As an initial example, the following beans work to some degree on Piranha Micro A (which doens't implement Enterprise Beans)

Async

import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateless;

@Stateless
public class AsyncBean {
    private static final Logger LOGGER = Logger.getLogger(AsyncBean.class.getName());

    @Asynchronous
    public Future<Integer> multiply(int number1, int number2) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
            Thread.interrupted();
            LOGGER.log(SEVERE, null, ex);
        }

        return new AsyncResult<>(number1 * number2);
    }

}

Singleton

import jakarta.ejb.Singleton;
import jakarta.annotation.PostConstruct;

@Singleton
public class SingletonBean {
    private StringBuilder builder;

    @PostConstruct
    private void postConstruct() {
        builder = new StringBuilder();
    }
    
    public void addValue(String value) {
        builder.append(value);
    }
    
    public String getAccumulatedValues() {
        return builder.toString();
    }
}

Lock

import jakarta.ejb.Lock;
import jakarta.ejb.Singleton;
import jakarta.annotation.PostConstruct;

@Singleton
@Lock(READ)
public class SingletonBean {
    private StringBuilder builder;

    @PostConstruct
    private void postConstruct() {
        builder = new StringBuilder();
    }
    
    @Lock(WRITE)
    public void addValue(String value) {
        builder.append(value);
    }
    
    public String getAccumulatedValues() {
        return builder.toString();
    }
}

Lock and EJB-style Interceptors

import jakarta.ejb.Lock;
import jakarta.ejb.Singleton;
import jakarta.annotation.PostConstruct;
import jakarta.interceptor.Interceptors;

@Singleton
@Lock(READ)
@Interceptors(InterceptorA.class)
public class SingletonBean {
    private StringBuilder builder;

    @PostConstruct
    private void postConstruct() {
        builder = new StringBuilder();
    }
    
    @Lock(WRITE)
    @Interceptors(InterceptorB.class)
    public void addValue(String value) {
        builder.append(value);
    }
    
    public String getAccumulatedValues() {
        return builder.toString();
    }
}

EJB method injection by bean name

import jakarta.ejb.Stateless;
import jakarta.ejb.EJB;

@Stateless
public class InjectedBean {

    SomeInterface injectedBean;

    @EJB(beanName = "SomeBean")
    public void setSomeBean(SomeInterface bean) {
      this.injectedBean = bean;
    }

}

Transaction

import jakarta.ejb.Stateless;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

@Stateless
public class MyEntityService {

    @PersistenceContext
    private EntityManager entityManager;

    public void save(MyEntity entity ) {
        // Transaction is automatically active here
        entityManager.persist(entity);
    }

    public MyEntity load(int id) {
        return entityManager.find(MyEntity.class, id);
    }
}

About

Jakarta Enterprise Beans Lite implementation

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
license.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages