List of usage examples for javax.naming Reference add
public void add(RefAddr addr)
From source file:com.caricah.iotracah.datastore.IotDataSource.java
public void setupDatasource(String driver, String dbUrl, String username, String password) throws NamingException { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); System.setProperty(Context.PROVIDER_URL, "file:////tmp"); Context ctx = new InitialContext(); // Construct DriverAdapterCPDS reference Reference cpdsRef = new Reference("org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS", "org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS", null); cpdsRef.add(new StringRefAddr("driver", driver)); cpdsRef.add(new StringRefAddr("url", dbUrl)); cpdsRef.add(new StringRefAddr("user", username)); cpdsRef.add(new StringRefAddr("password", password)); ctx.rebind("jdbc_cpds", cpdsRef); Reference ref = new Reference("org.apache.commons.dbcp2.datasources.SharedPoolDataSource", "org.apache.commons.dbcp2.datasources.SharedPoolDataSourceFactory", null); ref.add(new StringRefAddr("dataSourceName", "jdbc_cpds")); ref.add(new StringRefAddr("defaultMaxTotal", "100")); ref.add(new StringRefAddr("defaultMaxIdle", "30")); ref.add(new StringRefAddr("defaultMaxWaitMillis", "10000")); ctx.rebind("jdbc_commonpool", ref); }
From source file:com.stratelia.silverpeas.versioning.jcr.impl.AbstractJcrTestCase.java
@Resource public void setDataSource(DataSource datasource) { this.datasource = datasource; try {/*from w ww . ja va 2 s . c o m*/ prepareJndi(); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); InitialContext ic = new InitialContext(env); Properties properties = new Properties(); properties.load(PathTestUtil.class.getClassLoader().getResourceAsStream("jdbc.properties")); // Construct BasicDataSource reference Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr("driverClassName", properties.getProperty("driverClassName", "org.postgresql.Driver"))); ref.add(new StringRefAddr("url", properties.getProperty("url", "jdbc:postgresql://localhost:5432/postgres"))); ref.add(new StringRefAddr("username", properties.getProperty("username", "postgres"))); ref.add(new StringRefAddr("password", properties.getProperty("password", "postgres"))); ref.add(new StringRefAddr("maxActive", "4")); ref.add(new StringRefAddr("maxWait", "5000")); ref.add(new StringRefAddr("removeAbandoned", "true")); ref.add(new StringRefAddr("removeAbandonedTimeout", "5000")); rebind(ic, JNDINames.DATABASE_DATASOURCE, ref); rebind(ic, JNDINames.ADMIN_DATASOURCE, ref); } catch (NamingException nex) { nex.printStackTrace(); } catch (IOException nex) { nex.printStackTrace(); } }
From source file:com.alibaba.wasp.jdbcx.JdbcDataSource.java
/** * Get a new reference for this object, using the current settings. * //from ww w . ja va2 s .c o m * @return the new reference */ public Reference getReference() { String factoryClassName = JdbcDataSourceFactory.class.getName(); Reference ref = new Reference(getClass().getName(), factoryClassName, null); ref.add(new StringRefAddr("url", url)); ref.add(new StringRefAddr("user", userName)); ref.add(new StringRefAddr("password", convertToString(passwordChars))); ref.add(new StringRefAddr("loginTimeout", String.valueOf(loginTimeout))); ref.add(new StringRefAddr("description", description)); return ref; }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from w w w . j a v a 2s .c o m*/ public void testGetObjectInstance_fnblcore() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblcore"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("ss", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *///from w w w. ja va 2s. c o m public void testGetObjectInstance_fnbluser() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpwd", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//*from w w w . j a v a2 s . c o m*/ public void testGetObjectInstance_fnblds() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblds"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//* ww w.j a v a 2 s. co m*/ public void testGetObjectInstance_fnbluser_routing_no_partition() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser-routing-nopartition"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof RoutingDataSource); BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource"); assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpwd", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); assertEquals(15, bds.getNumTestsPerEvictionRun()); // coming from db.xml }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *///from www . ja va 2 s . c o m public void testGetObjectInstance_WitWrongJNDIName() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbl"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr url = new StringRefAddr("url", "jdbc:hsqldb:hsql://localhost/funambol"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.tomcat.dbcp.dbcp.BasicDataSource); BasicDataSource bds = (BasicDataSource) result; assertNull(bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); // // These are read from the db.xml since there is not the fnbl.xml file // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. */// w w w . jav a 2 s.c o m public void testGetObjectInstance_fnbluser_routing_with_partition() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnbluser-routing-with-partition"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr userName = new StringRefAddr("minIdle", "7"); ref.add(userName); // // At the end this should be overwritten by the value in the fnblds.xml file // RefAddr url = new StringRefAddr("url", "this-is-the-url"); ref.add(url); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof RoutingDataSource); RoutingDataSource rds = (RoutingDataSource) result; rds.init(); rds.configure(); Map<String, DataSource> datasources = rds.getDataSources(); assertEquals("Wrong number of datasources", 3, datasources.size()); BasicDataSource ds1 = (BasicDataSource) datasources.get("user_part1"); assertNotNull("user_part1 must be not null", ds1); assertEquals("sa", ds1.getUsername()); assertEquals("", ds1.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part1", ds1.getUrl()); assertEquals(15, ds1.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds1.getMinIdle()); // set with StringRefAddr BasicDataSource ds2 = (BasicDataSource) datasources.get("user_part2"); assertNotNull("user_part2 must be not null", ds2); assertEquals("sa", ds2.getUsername()); assertEquals("", ds2.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part2", ds2.getUrl()); assertEquals(15, ds2.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds2.getMinIdle()); // set with StringRefAddr BasicDataSource ds3 = (BasicDataSource) datasources.get("user_part3"); assertNotNull("user_part3 must be not null", ds3); assertEquals("sa", ds3.getUsername()); assertEquals("", ds3.getPassword()); assertEquals("jdbc:hsqldb:mem:user_part3", ds3.getUrl()); assertEquals(15, ds3.getNumTestsPerEvictionRun()); // from db.xml assertEquals(7, ds3.getMinIdle()); // set with StringRefAddr BasicDataSource bds = (BasicDataSource) PrivateAccessor.getField(result, "defaultDataSource"); assertEquals(7, bds.getMinIdle()); // // These are read from the fnbluser.xml // assertEquals("fnbluserpartition", bds.getUsername()); assertEquals("fnblpwd", bds.getPassword()); assertEquals("org.fnbluser", bds.getDriverClassName()); assertEquals("jdbc:hsqldb:hsql://localhost/user", bds.getUrl()); assertTrue(rds.getPartitioningCriteria() instanceof MockPartitioningCriteria); }
From source file:com.funambol.server.db.DataSourceFactoryTest.java
/** * Test of getObjectInstance method, of class DataSourceFactory. *//* w ww. ja va2 s.co m*/ public void testGetObjectInstance_fnblcore_with_wrappedFactory() throws Exception { DataSourceFactory dataSourceFactory = new DataSourceFactory(); InitialContext context = new InitialContext(); Hashtable environment = new Hashtable(); Name name = new CompositeName("fnblcore"); Reference ref = new Reference("javax.sql.DataSource"); RefAddr wrFactory = new StringRefAddr("wrappedFactory", "org.apache.commons.dbcp.BasicDataSourceFactory"); ref.add(wrFactory); RefAddr minIdle = new StringRefAddr("minIdle", "3"); ref.add(minIdle); Object result = dataSourceFactory.getObjectInstance(ref, name, context, environment); assertTrue(result instanceof org.apache.commons.dbcp.BasicDataSource); org.apache.commons.dbcp.BasicDataSource bds = (org.apache.commons.dbcp.BasicDataSource) result; assertEquals(3, bds.getMinIdle()); // // These are read from the db.xml // assertEquals("db", bds.getUsername()); assertEquals("org.hsqldb.jdbcDriver", bds.getDriverClassName()); // // These are read from the fnblds.xml // assertEquals("ss", bds.getPassword()); assertEquals("jdbc:hsqldb:hsql://localhost/funambol", bds.getUrl()); }