Example usage for javax.naming InitialContext rebind

List of usage examples for javax.naming InitialContext rebind

Introduction

In this page you can find the example usage for javax.naming InitialContext rebind.

Prototype

public void rebind(Name name, Object obj) throws NamingException 

Source Link

Usage

From source file:SetupJNDIDataSource.java

public static void main(String args[]) {
    try {/*www. j a va 2  s  .  c  o m*/
        startRegistry();
        ConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();
        dataSource.setUser("username");
        dataSource.setPassword("password");
        dataSource.setServerName("localhost");
        dataSource.setPort(3306);
        dataSource.setDatabaseName("databasename");

        InitialContext context = createContext();
        context.rebind("HrDS", dataSource);

    } catch (Exception e) {
        System.out.println("SetupJNDIDataSource err: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:SetupJNDIDataSource.java

public static void main(String args[]) {
    if (args.length < 2) {
        System.out.println("usage: SetupJNDIDataSource username password");
        return;//from  w w  w .j a v  a  2s  .  co m
    }

    try {
        startRegistry();

        ConnectionPoolDataSource dataSource = createDataSource(args[0], args[1]);

        InitialContext context = createContext();
        context.rebind("HrDS", dataSource);

    } catch (Exception e) {
        System.out.println("SetupJNDIDataSource err: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.silverpeas.admin.DomainTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    context = new ClassPathXmlApplicationContext(
            new String[] { "spring-admin-spacecomponents-embbed-datasource.xml", "spring-domains.xml" });
    dataSource = context.getBean("jpaDataSource", DataSource.class);
    InitialContext ic = new InitialContext();
    ic.rebind("jdbc/Silverpeas", dataSource);
    DBUtil.getInstanceForTest(dataSource.getConnection());
}

From source file:com.silverpeas.admin.SpacesManagersTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    context = new ClassPathXmlApplicationContext(
            new String[] { "spring-admin-spacemanagers-embbed-datasource.xml", "spring-domains.xml" });
    dataSource = context.getBean("jpaDataSource", DataSource.class);
    InitialContext ic = new InitialContext();
    ic.rebind("jdbc/Silverpeas", dataSource);
    DBUtil.getInstanceForTest(dataSource.getConnection());
}

From source file:com.stratelia.webactiv.util.DBUtilTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    context = new ClassPathXmlApplicationContext(new String[] { "spring-h2-datasource.xml" });
    dataSource = context.getBean("dataSource", DataSource.class);
    InitialContext ic = new InitialContext();
    ic.rebind(DATASOURCE_NAME, dataSource);
    DBUtil.getInstanceForTest(dataSource.getConnection());
}

From source file:com.silverpeas.admin.UsersAndGroupsTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    context = new ClassPathXmlApplicationContext(
            new String[] { "spring-domains-embbed-datasource.xml", "spring-domains.xml" });
    dataSource = context.getBean("jpaDataSource", DataSource.class);
    InitialContext ic = new InitialContext();
    ic.rebind("jdbc/Silverpeas", dataSource);
    DBUtil.getInstanceForTest(dataSource.getConnection());
}

From source file:net.sf.taverna.t2.provenance.api.ProvenanceAccess.java

/**
 * Initialises a named JNDI DataSource if not already set up externally.
 * The DataSource is named jdbc/taverna//from  w  ww  . j  av a  2 s  .c o m
 *
 * @param driverClassName - the classname for the driver to be used.
 * @param jdbcUrl - the jdbc connection url
 * @param username - the username, if required (otherwise null)
 * @param password - the password, if required (oteherwise null)
 * @param minIdle - if the driver supports multiple connections, then the minumum number of idle connections in the pool
 * @param maxIdle - if the driver supports multiple connections, then the maximum number of idle connections in the pool
 * @param maxActive - if the driver supports multiple connections, then the minumum number of connections in the pool
 */
public static void initDataSource(String driverClassName, String jdbcUrl, String username, String password,
        int minIdle, int maxIdle, int maxActive) {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.osjava.sj.memory.MemoryContextFactory");
    System.setProperty("org.osjava.sj.jndi.shared", "true");

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverClassName);
    ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setMaxIdle(maxIdle);
    ds.setDefaultAutoCommit(true);
    if (username != null) {
        ds.setUsername(username);
    }
    if (password != null) {
        ds.setPassword(password);
    }

    ds.setUrl(jdbcUrl);

    InitialContext context;
    try {
        context = new InitialContext();
        context.rebind("jdbc/taverna", ds);
    } catch (NamingException ex) {
        logger.error("Problem rebinding the jdbc context: " + ex);
    }

}

From source file:com.silverpeas.admin.SpacesAndComponentsTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    context = new ClassPathXmlApplicationContext(
            new String[] { "spring-admin-spacecomponents-embbed-datasource.xml", "spring-domains.xml" });
    dataSource = context.getBean("jpaDataSource", DataSource.class);
    organizationController = context.getBean(OrganizationController.class);
    admin = context.getBean(Admin.class);
    InitialContext ic = new InitialContext();
    ic.rebind("jdbc/Silverpeas", dataSource);
    DBUtil.getInstanceForTest(dataSource.getConnection());
}

From source file:com.francetelecom.clara.cloud.commons.toggles.PaasJndiStateRepository.java

@Override
public void setFeatureState(FeatureState featureState) {
    String featureName = featureState.getFeature().name();
    try {// www  .java 2s . c o m
        InitialContext jndiContext = getInitialContext();
        jndiContext.rebind(featureName, Boolean.toString(featureState.isEnabled()));
        String users = StringUtils.join(featureState.getUsers(), ", ");
        //for(String user:featureState.getUsers()) users += user+", ";
        jndiContext.rebind(featureName + ".users", users);
    } catch (NamingException e) {
        logger.error("unable to save state of feature " + featureName + " in jndi", e);
    }
}

From source file:com.sf.ddao.UseStatementFactoryTest.java

protected void setUp() throws Exception {
    super.setUp();
    JDBCMockObjectFactory factory = getJDBCMockObjectFactory();
    MockDataSource ds = factory.getMockDataSource();
    MockContextFactory.setAsInitial();/*w ww  . ja v  a2 s.com*/
    InitialContext context = new InitialContext();
    context.rebind(JNDIDataSourceHandler.DS_CTX_PREFIX + "jdbc/testdb", ds);
    this.injector = Guice.createInjector(new ChainModule(UserDao.class));
}