List of usage examples for org.springframework.jdbc.datasource.lookup JndiDataSourceLookup JndiDataSourceLookup
public JndiDataSourceLookup()
From source file:ua.com.rocketlv.spb.Application.java
@Bean public DataSource dataSource() { JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); DataSource dataSource = dataSourceLookup.getDataSource("java:comp/env/jdbc/testinfo"); return dataSource; }
From source file:net.bluewizardhat.tfa.web.config.PersistenceJpaConfig.java
@Bean public DataSource dataSource() { JndiDataSourceLookup lookup = new JndiDataSourceLookup(); return lookup.getDataSource(jndiDatasource); }
From source file:hiloTestear.ESNConfiguracionPersistencia.java
@Bean public DataSource dataSource() { final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); dsLookup.setResourceRef(true);// w ww . j a v a 2s.co m DataSource dataSource = dsLookup.getDataSource(environment.getProperty(PROPERTY_NAME_DATABASE_JNDI)); return dataSource; }
From source file:com.p6spy.engine.spy.MultipleDataSourceTest.java
@Test public void testSpyEnabledDataSource() throws SQLException { DataSource spyDs1 = new JndiDataSourceLookup().getDataSource("jdbc/spyDs1"); // The spy data sources should be spy enabled validateSpyEnabled(spyDs1);/*from w w w . j a v a 2 s . com*/ // verify that the correct database driver was used assertTrue(spyDs1.getConnection().getMetaData().getDatabaseProductName().contains("H2")); DataSource spyDs3 = new JndiDataSourceLookup().getDataSource("jdbc/spyDs3"); // The spy data sources should be spy enabled validateSpyEnabled(spyDs3); // verify that the correct database driver was used assertTrue(spyDs3.getConnection().getMetaData().getDatabaseProductName().contains("HSQL")); }
From source file:org.wte4j.ui.config.StandaloneJPAConfig.java
@Bean @Lazy/*from w ww . j a v a2 s .c o m*/ public DataSource wteInternalDataSource() { if (env.containsProperty("wte4j.jdbc.jndi")) { JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); DataSource dataSource = dsLookup.getDataSource(env.getProperty("wte4j.jdbc.jndi")); return dataSource; } else if (env.containsProperty("wte4j.jdbc.url")) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(env.getProperty("wte4j.jdbc.url")); dataSource.setDriverClassName(env.getProperty("wte4j.jdbc.driver")); dataSource.setUsername(env.getProperty("wte4j.jdbc.user")); dataSource.setPassword(env.getProperty("wte4j.jdbc.password")); return dataSource; } else { logger.info("no database configured"); logger.info("try to start hsql database"); hsqlServer().start(); hsqlServerIsRunning = true; logger.info("hsql server started"); BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:hsqldb:hsql://localhost/wte4j"); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUsername("sa"); return dataSource; } }
From source file:com.p6spy.engine.spy.DataSourceTest.java
@Test public void testGenericDataSourceWithDriverManager() throws Exception { // Create and bind the real data source // Note: This will get the driver from the DriverManager realDs = new TestBasicDataSource(); realDs.setDriverClassName(driverClass); realDs.setUrl(url);/*from w ww . ja va 2s .c o m*/ realDs.setUsername(user); realDs.setPassword(password); realDs.setUseDriverManager(true); realDsResource = new Resource("jdbc/realDs", realDs); P6TestUtil.setupTestData(realDs); // get the data source from JNDI DataSource ds = new JndiDataSourceLookup().getDataSource("jdbc/spyDs"); assertNotNull("JNDI data source not found", ds); // get the connection con = ds.getConnection(); // verify that the connection class is a proxy assertTrue("Connection is not a proxy", ProxyFactory.isProxy(con)); Statement stmt = con.createStatement(); stmt.execute("select 1 from customers"); stmt.close(); assertTrue(((P6TestLogger) P6LogQuery.getLogger()).getLastEntry().indexOf("select 1") != -1); assertEquals("Incorrect number of spy log messages", 1, ((P6TestLogger) P6LogQuery.getLogger()).getLogs().size()); }
From source file:com.p6spy.engine.spy.MultipleDataSourceTest.java
@Test public void testNotSpyEnabledDataSource() throws SQLException { // the read data sources should NOT be spy enabled DataSource realDs1 = new JndiDataSourceLookup().getDataSource("jdbc/realDs1"); validateNotSpyEnabled(realDs1);// w w w . j av a 2s.com DataSource realDs2 = new JndiDataSourceLookup().getDataSource("jdbc/realDs2"); validateNotSpyEnabled(realDs2); DataSource realDs3 = new JndiDataSourceLookup().getDataSource("jdbc/realDs3"); validateNotSpyEnabled(realDs3); }
From source file:com.p6spy.engine.spy.DataSourceTest.java
@Test public void testGenericDataSourceWithOutDriverManager() throws Exception { // Create and bind the real data source // Note: This will get the driver from the DriverManager realDs = new TestBasicDataSource(); realDs.setDriverClassName(driverClass); realDs.setUrl(url);/* ww w . jav a2 s. c o m*/ realDs.setUsername(user); realDs.setPassword(password); realDs.setUseDriverManager(false); realDsResource = new Resource("jdbc/realDs", realDs); P6TestUtil.setupTestData(realDs); // get the data source from JNDI DataSource ds = new JndiDataSourceLookup().getDataSource("jdbc/spyDs"); assertNotNull("JNDI data source not found", ds); // get the connection con = ds.getConnection(); // verify that the connection class is a proxy assertTrue("Connection is not a proxy", ProxyFactory.isProxy(con)); }
From source file:com.jhonyu.framework.frame.datasource.RoutingDataSource.java
/** * Set the DataSourceLookup implementation to use for resolving data source name Strings in the * {@link #setTargetDataSources targetDataSources} map. <p>Default is a * {@link JndiDataSourceLookup}, allowing the JNDI names of application server DataSources to * be specified directly./*w w w. j a va 2 s. c o m*/ */ public void setDataSourceLookup(DataSourceLookup dataSourceLookup) { this.dataSourceLookup = (dataSourceLookup != null ? dataSourceLookup : new JndiDataSourceLookup()); }
From source file:com.p6spy.engine.spy.XADataSourceTest.java
@Before public void setUpXADataSourceTest() throws NamingException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { final P6TestLoadableOptions testOptions = P6TestOptions.getActiveInstance(); jndiResources = new ArrayList<Resource>(); poolingDSs = new ArrayList<PoolingDataSource>(); tm = TransactionManagerServices.getTransactionManager(); // in test DS setup {/* ww w . j a v a2s . com*/ final XADataSource realInTestDs = (XADataSource) P6Util .forName(testOptions.getXaDataSource().getClass().getName()).newInstance(); setXADSProperties(realInTestDs, testOptions.getUrl().replace(":p6spy", ""), testOptions.getUser(), testOptions.getPassword()); jndiResources.add(new Resource("jdbc/realInTestDs", realInTestDs)); final PoolingDataSource inTestDs = new PoolingDataSource(); inTestDs.setClassName(P6DataSource.class.getName()); inTestDs.setUniqueName("jdbc/inTestDs"); inTestDs.setMaxPoolSize(10); inTestDs.getDriverProperties().setProperty("realDataSource", "jdbc/realInTestDs"); inTestDs.setAllowLocalTransactions(true); inTestDs.init(); jndiResources.add(new Resource("jdbc/inTestDs", inTestDs)); poolingDSs.add(inTestDs); } // fixed DS setup { final XADataSource realFixedDs = (XADataSource) P6Util.forName("org.h2.jdbcx.JdbcDataSource") .newInstance(); setXADSProperties(realFixedDs, "jdbc:h2:mem:p6spy_realFixedDs", "sa", "sa"); jndiResources.add(new Resource("jdbc/realFixedDs", realFixedDs)); final PoolingDataSource fixedDs = new PoolingDataSource(); fixedDs.setClassName(P6DataSource.class.getName()); fixedDs.setUniqueName("jdbc/fixedDs"); fixedDs.setMaxPoolSize(10); fixedDs.getDriverProperties().setProperty("realDataSource", "jdbc/realFixedDs"); fixedDs.setAllowLocalTransactions(true); fixedDs.init(); jndiResources.add(new Resource("jdbc/fixedDs", fixedDs)); poolingDSs.add(fixedDs); } // liquibase opens it's own transaction => keep it out of ours try { P6TestUtil.setupTestData(new JndiDataSourceLookup().getDataSource("jdbc/inTestDs")); P6TestUtil.setupTestData(new JndiDataSourceLookup().getDataSource("jdbc/fixedDs")); } catch (LiquibaseException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { tm.begin(); // TODO move to liquibase? cleanData(new JndiDataSourceLookup().getDataSource("jdbc/inTestDs")); cleanData(new JndiDataSourceLookup().getDataSource("jdbc/fixedDs")); tm.commit(); } catch (NotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicMixedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (HeuristicRollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RollbackException e) { // TODO Auto-generated catch block e.printStackTrace(); } }