Search in sources :

Example 91 with RefAddr

use of javax.naming.RefAddr in project tomcat by apache.

the class PerUserPoolDataSourceFactory method getNewInstance.

// Avoid warnings on deserialization
@SuppressWarnings("unchecked")
@Override
protected InstanceKeyDataSource getNewInstance(final Reference ref) throws IOException, ClassNotFoundException {
    final PerUserPoolDataSource pupds = new PerUserPoolDataSource();
    RefAddr refAddr = ref.get("defaultMaxTotal");
    if (refAddr != null && refAddr.getContent() != null) {
        pupds.setDefaultMaxTotal(parseInt(refAddr));
    }
    refAddr = ref.get("defaultMaxIdle");
    if (refAddr != null && refAddr.getContent() != null) {
        pupds.setDefaultMaxIdle(parseInt(refAddr));
    }
    refAddr = ref.get("defaultMaxWaitMillis");
    if (refAddr != null && refAddr.getContent() != null) {
        pupds.setDefaultMaxWait(Duration.ofMillis(parseInt(refAddr)));
    }
    refAddr = ref.get("perUserDefaultAutoCommit");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserDefaultAutoCommit((Map<String, Boolean>) deserialize(serialized));
    }
    refAddr = ref.get("perUserDefaultTransactionIsolation");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserDefaultTransactionIsolation((Map<String, Integer>) deserialize(serialized));
    }
    refAddr = ref.get("perUserMaxTotal");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserMaxTotal((Map<String, Integer>) deserialize(serialized));
    }
    refAddr = ref.get("perUserMaxIdle");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserMaxIdle((Map<String, Integer>) deserialize(serialized));
    }
    refAddr = ref.get("perUserMaxWaitMillis");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserMaxWaitMillis((Map<String, Long>) deserialize(serialized));
    }
    refAddr = ref.get("perUserDefaultReadOnly");
    if (refAddr != null && refAddr.getContent() != null) {
        final byte[] serialized = (byte[]) refAddr.getContent();
        pupds.setPerUserDefaultReadOnly((Map<String, Boolean>) deserialize(serialized));
    }
    return pupds;
}
Also used : RefAddr(javax.naming.RefAddr)

Example 92 with RefAddr

use of javax.naming.RefAddr in project tomcat by apache.

the class SharedPoolDataSourceFactory method getNewInstance.

@Override
protected InstanceKeyDataSource getNewInstance(final Reference ref) {
    final SharedPoolDataSource spds = new SharedPoolDataSource();
    final RefAddr ra = ref.get("maxTotal");
    if (ra != null && ra.getContent() != null) {
        spds.setMaxTotal(Integer.parseInt(ra.getContent().toString()));
    }
    return spds;
}
Also used : RefAddr(javax.naming.RefAddr)

Example 93 with RefAddr

use of javax.naming.RefAddr in project druid by alibaba.

the class DruidDataSourceFactoryTest method test_factory.

@SuppressWarnings("serial")
public void test_factory() throws Exception {
    DruidDataSourceFactory factory = new DruidDataSourceFactory();
    Assert.assertNull(factory.getObjectInstance(null, null, null, null));
    Assert.assertNull(factory.getObjectInstance(new Reference("javax.sql.Date"), null, null, null));
    Reference ref = new Reference("javax.sql.DataSource");
    ref.add(new RefAddr("user") {

        @Override
        public Object getContent() {
            return null;
        }
    });
    ref.add(new RefAddr("defaultReadOnly") {

        @Override
        public Object getContent() {
            return Boolean.TRUE;
        }
    });
    factory.getObjectInstance(ref, null, null, new Hashtable<Object, Object>());
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference) DruidDataSourceFactory(com.alibaba.druid.pool.DruidDataSourceFactory)

Example 94 with RefAddr

use of javax.naming.RefAddr in project rabbitmq-jms-client by rabbitmq.

the class RMQConnectionFactoryTest method removeRefProperty.

/**
 * Remove property from a Reference (as a RefAddr)
 *
 * @param ref          - the reference
 * @param propertyName - the name of the property to remove
 */
private static void removeRefProperty(Reference ref, String propertyName) {
    if (propertyName == null)
        return;
    int numProps = ref.size();
    for (int i = 0; i < numProps; ++i) {
        RefAddr ra = ref.get(i);
        if (ra.getType().equals(propertyName)) {
            ref.remove(i--);
            numProps--;
        }
    }
}
Also used : RefAddr(javax.naming.RefAddr) StringRefAddr(javax.naming.StringRefAddr)

Aggregations

RefAddr (javax.naming.RefAddr)94 Reference (javax.naming.Reference)60 NamingException (javax.naming.NamingException)23 StringRefAddr (javax.naming.StringRefAddr)18 Properties (java.util.Properties)16 ObjectFactory (javax.naming.spi.ObjectFactory)12 InitialContext (javax.naming.InitialContext)9 Method (java.lang.reflect.Method)7 NameNotFoundException (javax.naming.NameNotFoundException)6 EjbRef (org.apache.naming.EjbRef)5 ResourceRef (org.apache.naming.ResourceRef)5 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)5 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 Enumeration (java.util.Enumeration)4 DataSource (javax.sql.DataSource)4 BeanInfo (java.beans.BeanInfo)3 PropertyDescriptor (java.beans.PropertyDescriptor)3 ResourceLinkRef (org.apache.naming.ResourceLinkRef)3