List of usage examples for javax.naming InitialContext InitialContext
public InitialContext() throws NamingException
From source file:de.tud.inf.db.sparqlytics.bench.LDBCBenchmark.java
@AfterClass public static void unbindRepository() throws NamingException { InitialContext ctx = new InitialContext(); Repository repository = (Repository) ctx.lookup("ldbc"); Slf4jReporter.forRegistry(repository.getStatistics()).withLoggingLevel(Slf4jReporter.LoggingLevel.INFO) .prefixedWith("after:").build().report(); ctx.unbind("ldbc"); }
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.wso2telco.gsma.authenticators.DBUtils.java
/** * Initialize datasources./*from ww w.ja va 2s. c o m*/ * * @throws AuthenticatorException the authenticator exception */ private static void initializeDatasources() throws AuthenticatorException { if (mConnectDatasource != null) { return; } String dataSourceName = null; try { Context ctx = new InitialContext(); ConfigurationService configurationService = new ConfigurationServiceImpl(); dataSourceName = configurationService.getDataHolder().getMobileConnectConfig().getDataSourceName(); mConnectDatasource = (DataSource) ctx.lookup(dataSourceName); } catch (NamingException e) { handleException("Error while looking up the data source: " + dataSourceName, e); } }
From source file:org.cauldron.execution.ContextUtils.java
public Task find(String name) { try {//w w w. j a v a 2 s. co m InitialContext ic = new InitialContext(); return (Task) ic.lookup(prefix + name); } catch (NamingException e) { ContextImpl.log.error("JNDI exception while finding task named " + name + " : " + e.getMessage()); return null; } }
From source file:com.taobao.ad.es.common.datasource.DataSourceFactory.java
public Connection getConnection(String contextPath, int dsType, String dataSource) throws BeansException, SQLException, NamingException { Connection connection = null; switch (dsType) { case JobData.JOBDATA_DATA_DATASOURCE_TYPE_DYNAMIC: // BeanFactoryLocator sysCtxLocator = // SingletonBeanFactoryLocator.getInstance(WebAgentConstants.DATASOURCE_CONTEXT); // BeanFactoryReference brf = // sysCtxLocator.useBeanFactory(WebAgentConstants.DATASOURCE_CONTEXT_KEY); // connection = ((DataSource) // brf.getFactory().getBean(dataSource)).getConnection(); AbstractXmlApplicationContext context = null; if (StringUtils.isEmpty(contextPath)) { context = new ClassPathXmlApplicationContext("classpath:es-agent-ds.xml"); } else {// w w w . j av a2 s . c o m context = new FileSystemXmlApplicationContext(contextPath); } connection = ((DataSource) context.getBean(dataSource)).getConnection(); break; default: Context cxt = new InitialContext(); Context envCtx = (Context) cxt.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/" + dataSource); connection = ds.getConnection(); break; } return connection; }
From source file:com.esa.infocontrol.data.jdbc.BaseDataJDBC.java
public static DataSource getDataSourceByName(String name) { DataSource ds = null;/*from ww w . j av a 2 s. c o m*/ try { InitialContext ic = new InitialContext(); ds = (DataSource) ic.lookup("jdbc/" + name); } catch (NamingException ex) { java.util.logging.Logger.getLogger(BaseDataJDBC.class.getName()).log(Level.SEVERE, null, ex); } return ds; }
From source file:sequrity.LoginService.java
public Korisnik loadUserByEmail(String email) throws Exception { Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); EntityManagerFactory emf = (EntityManagerFactory) envCtx.lookup("ime"); EntityManager em = emf.createEntityManager(); try {/*from ww w . ja v a2 s .co m*/ return (Korisnik) em.createNamedQuery("Profesor.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException e) { try { return (Korisnik) em.createNamedQuery("Student.findByEmail").setParameter("email", email) .getSingleResult(); } catch (NoResultException ex) { throw new Exception("Korisnik ne postoji u sistemu."); } } }
From source file:com.example.switchyard.idempotent.jpa.IdempotentJpaConsumer.java
private static TransactionManager getTransactionManager() { try {/*from w ww .j a v a2 s . co m*/ return (TransactionManager) new InitialContext().lookup("java:jboss/TransactionManager"); } catch (NamingException e) { throw new RuntimeException(e); } }
From source file:org.wso2.carbon.metrics.impl.ReporterTest.java
public static Test suite() { return new TestSetup(new TestSuite(ReporterTest.class)) { protected void setUp() throws Exception { DataSource dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", ""); template = new JdbcTemplate(dataSource); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("dbscripts/h2.sql")); populator.populate(dataSource.getConnection()); // Create initial context System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); InitialContext ic = new InitialContext(); ic.createSubcontext("jdbc"); ic.bind("jdbc/WSO2MetricsDB", dataSource); // Set setup system property to cover database creator logic System.setProperty("setup", ""); }// ww w .j a v a 2 s. co m protected void tearDown() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); } }; }
From source file:org.wso2.carbon.metrics.jdbc.core.BaseReporterTest.java
@AfterSuite protected static void destroy() throws Exception { if (logger.isInfoEnabled()) { logger.info("Unbinding jdbc/WSO2MetricsDB"); }//from w w w. j a v a 2s .c o m InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); if (logger.isInfoEnabled()) { logger.info("Stopping reporters"); } metrics.deactivate(); }