@Override public Object getObjectInstance(Object refObj, Name nm, Context ctx, Hashtable<?,?> env) throws Exception { final Reference ref = (Reference) refObj; final String className = ref.getClassName(); if (className != null && className.equals(DATASOURCE_CLASS_NAME)) { P6DataSource dataSource; try { dataSource = (P6DataSource) Class.forName(className).newInstance(); } catch (Exception ex) { throw new RuntimeException("Unable to create DataSource of " + "class '" + className + "': " + ex.toString()); } // name of the real datasource dataSource.setRealDataSource((String) ref.get("dataSourceName").getContent()); return dataSource; } else { // Who's class is this anyway, I ask ya! return null; } } }
@Before public void setup() throws Exception { // make sure to reinit properly new P6TestFramework("ds") { }; user = "sa"; password ="sa"; // please note non-typical DB name // however it seems that the typical one "jdbc:h2:mem:p6spy" // caused authorization exception, see: https://github.com/p6spy/p6spy/issues/76 // in some test execution sequences (on some setups only) // I suspect non-proper cleanup in some of the previous tests causing this error // url = "jdbc:h2:mem:p6spy"; url = "jdbc:h2:mem:p6spyDSTest"; driverClass = "org.h2.Driver"; P6DataSource spyDs = new P6DataSource(); spyDs.setRealDataSource("jdbc/realDs"); spyDsResource = new Resource("jdbc/spyDs", spyDs); ((P6TestLogger) P6LogQuery.getLogger()).clearLogs(); }
@Before public void setUp() throws Exception { // make sure to reinit properly new P6TestFramework("ds") { }; jndiResources = new ArrayList<Resource>(); // create the real data sources and bind to jndi JdbcDataSource realDs1 = new JdbcDataSource(); realDs1.setUser("sa"); realDs1.setURL("jdbc:h2:mem:multids1"); jndiResources.add(new Resource("jdbc/realDs1", realDs1)); JdbcDataSource realDs2 = new JdbcDataSource(); realDs2.setUser("sa"); realDs2.setURL("jdbc:h2:mem:multids2"); jndiResources.add(new Resource("jdbc/realDs2", realDs2)); JDBCDataSource realDs3 = new JDBCDataSource(); realDs3.setUser("sa"); realDs3.setPassword(""); realDs3.setUrl("jdbc:hsqldb:mem:multids3"); jndiResources.add(new Resource("jdbc/realDs3", realDs3)); // create the spy wrapper data sources and bind to jndi P6DataSource spyDs1 = new P6DataSource(); spyDs1.setRealDataSource("jdbc/realDs1"); jndiResources.add(new Resource("jdbc/spyDs1", spyDs1)); P6DataSource spyDs3 = new P6DataSource(); spyDs3.setRealDataSource("jdbc/realDs3"); jndiResources.add(new Resource("jdbc/spyDs3", spyDs3)); // reset captured log messages ((P6TestLogger) P6LogQuery.getLogger()).clearLogs(); }
@Override public Object getObjectInstance(Object refObj, Name nm, Context ctx, Hashtable<?,?> env) throws Exception { final Reference ref = (Reference) refObj; final String className = ref.getClassName(); if (className != null && className.equals(DATASOURCE_CLASS_NAME)) { P6DataSource dataSource; try { dataSource = (P6DataSource) Class.forName(className).newInstance(); } catch (Exception ex) { throw new RuntimeException("Unable to create DataSource of " + "class '" + className + "': " + ex.toString()); } // name of the real datasource dataSource.setRealDataSource((String) ref.get("dataSourceName").getContent()); return dataSource; } else { // Who's class is this anyway, I ask ya! return null; } } }