I would like to reuse the safetype enumeration, which I should already specify an argument for @Resource annotation, which requires String compile time constant. I did not find an elegant solution how to reuse DATASOURCE, except that I am enclosing:
public enum DATASOURCE { // Enum constants DataSource1, DataSource2; public final static String DataSource1_jndi = "java:/jdbc/DataSource1"; public final static String DataSource2_jndi = "java:/jdbc/DataSource2"; public String getJndiName() { switch(this) { case DataSource1: return DataSource1_jndi; case DataSource2: return DataSource2_jndi; default: throw new RuntimeException("Not defined jndi name for DATASOURCE " + this); } } }
Using the listing itself
public class DataSourceFactory { public static DataSource getDataSource(DATASOURCE ds) {
But now I would like to use the same DATASOURCE constant also in SessionBeans along with the @Resource annotation
@Stateless public class SomeSessionBean {
Any idea?
source share