List of usage examples for org.springframework.jdbc.datasource.embedded EmbeddedDatabaseFactory getDatabase
public EmbeddedDatabase getDatabase()
From source file:ch.algotrader.cache.CacheTest.java
@BeforeClass public static void beforeClass() { context = new AnnotationConfigApplicationContext(); context.getEnvironment().setActiveProfiles("embeddedDataSource", "simulation"); // register in-memory db EmbeddedDatabaseFactory dbFactory = new EmbeddedDatabaseFactory(); dbFactory.setDatabaseType(EmbeddedDatabaseType.H2); dbFactory.setDatabaseName("testdb;MODE=MYSQL;DATABASE_TO_UPPER=FALSE"); database = dbFactory.getDatabase(); context.getDefaultListableBeanFactory().registerSingleton("dataSource", database); EngineManager engineManager = Mockito.mock(EngineManager.class); Mockito.when(engineManager.getCurrentEPTime()).thenReturn(new Date()); Mockito.when(engineManager.getCurrentEPTime()).thenReturn(new Date()); context.getDefaultListableBeanFactory().registerSingleton("engineManager", engineManager); AtomicReference<TransactionService> transactionService = new AtomicReference<>(); Engine engine = new NoopEngine(StrategyImpl.SERVER); context.getDefaultListableBeanFactory().registerSingleton("serverEngine", engine); ExternalMarketDataService externalMarketDataService = Mockito.mock(ExternalMarketDataService.class); context.getDefaultListableBeanFactory().registerSingleton("externalMarketDataService", externalMarketDataService);// w ww . j a va2 s.c om context.getDefaultListableBeanFactory().registerSingleton("historicalDataService", new NoopHistoricalDataServiceImpl()); Mockito.when(externalMarketDataService.getFeedType()).thenReturn(FeedType.IB.name()); // register Wirings context.register(CommonConfigWiring.class, CoreConfigWiring.class, EventDispatchWiring.class, EventDispatchPostInitWiring.class, HibernateWiring.class, CacheWiring.class, DaoWiring.class, ServiceWiring.class, SimulationWiring.class); context.refresh(); transactionService.set(context.getBean(TransactionService.class)); cache = context.getBean(CacheManager.class); txTemplate = context.getBean(TransactionTemplate.class); // create the database ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ClassPathResource("/db/h2/h2.sql")); DatabasePopulatorUtils.execute(dbPopulator, database); // populate the database SessionFactory sessionFactory = context.getBean(SessionFactory.class); Session session = sessionFactory.openSession(); Exchange exchange1 = new ExchangeImpl(); exchange1.setName("IDEALPRO"); exchange1.setCode("IDEALPRO"); exchange1.setTimeZone("US/Eastern"); session.save(exchange1); SecurityFamily family1 = new SecurityFamilyImpl(); family1.setName("FX"); family1.setTickSizePattern("0<0.1"); family1.setCurrency(Currency.USD); family1.setExchange(exchange1); family1.setTradeable(true); family1.setContractSize(1.0); securityFamilyId1 = (Long) session.save(family1); SecurityFamily family2 = new SecurityFamilyImpl(); family2.setName("NON_TRADEABLE"); family2.setTickSizePattern("0<0.1"); family2.setCurrency(Currency.USD); family2.setTradeable(false); family2.setContractSize(1.0); securityFamilyId2 = (Long) session.save(family2); Forex security1 = new ForexImpl(); security1.setSymbol("EUR.USD"); security1.setBaseCurrency(Currency.EUR); security1.setSecurityFamily(family1); securityId1 = (Long) session.save(security1); Forex security2 = new ForexImpl(); security2.setSymbol("GBP.USD"); security2.setBaseCurrency(Currency.GBP); security2.setSecurityFamily(family1); security2.setUnderlying(security1); securityId2 = (Long) session.save(security2); Strategy strategy1 = new StrategyImpl(); strategy1.setName(STRATEGY_NAME); strategyId1 = (Long) session.save(strategy1); Position position1 = new PositionImpl(); position1.setQuantity(222); position1.setStrategy(strategy1); position1.setSecurity(security2); position1.setCost(new BigDecimal(0.0)); position1.setRealizedPL(new BigDecimal(0.0)); session.save(position1); Property property1 = new PropertyImpl(); property1.setName(PROPERTY_NAME); property1.setDoubleValue(10.0); property1.setPropertyHolder(strategy1); session.save(property1); strategy1.getProps().put(PROPERTY_NAME, property1); Account account1 = new AccountImpl(); account1.setName("TEST"); account1.setBroker("TEST"); account1.setOrderServiceType(OrderServiceType.SIMULATION.toString()); accountId1 = (Long) session.save(account1); session.flush(); session.close(); }
From source file:sf.wicklet.gwt.site.server.db.H2Configurator.java
/** @param dbpath Absolute path relative to web application context root. */ public static EmbeddedDatabase createDatabase(final String dbpath, final String... initscripts) throws ClassNotFoundException { final EmbeddedDatabaseFactory f = new EmbeddedDatabaseFactory(); final ResourceDatabasePopulator p = new ResourceDatabasePopulator(); final ResourceLoader l = new DefaultResourceLoader(); final IWickletSupport support = Config.get().getSupport(); final File dbfile = support.getContextFile(dbpath + ".h2.db"); if (!dbfile.exists()) { for (final String s : initscripts) { p.addScript(l.getResource("file:" + support.getContextFile(s).getAbsolutePath())); }/*w w w .ja v a 2s . c om*/ } f.setDatabasePopulator(p); f.setDatabaseConfigurer(H2Configurator.getInstance(support.getContextFile(dbpath).getAbsolutePath())); // Database name is actually a don't care. f.setDatabaseName(TextUtil.fileName(dbpath)); return f.getDatabase(); }
From source file:com.github.javarch.persistence.orm.hibernate.conf.DataSourceH2Config.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { LOG.debug("Iniciando construo do EmbeddedDatabase H2..."); EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseType(EmbeddedDatabaseType.H2); DataSource ds = factory.getDatabase(); return ds;//w w w . ja v a2 s . c o m }
From source file:com.springsource.greenhouse.database.GreenhouseDatabaseInstallerTest.java
@Test public void runUpgrader() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseType(EmbeddedDatabaseType.H2); EmbeddedDatabase db = factory.getDatabase(); System.setProperty("security.encryptPassword", "foo"); System.setProperty("security.encryptSalt", new String(Hex.encode(KeyGenerators.secureRandom().generateKey()))); DatabaseUpgrader installer = new DatabaseUpgrader(db, new StandardEnvironment(), Encryptors.noOpText()); installer.run();/*from w ww . ja v a2s . c o m*/ installer.run(); DatabaseUpgrader installer2 = new DatabaseUpgrader(db, new StandardEnvironment(), Encryptors.noOpText()); installer2.run(); }
From source file:com.pramati.knowyou.config.MainConfig.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("knowyou"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }
From source file:de.uni_koeln.spinfo.maalr.login.config.H2Config.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("maalr-social-connect"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }
From source file:com.github.gabrielruiu.spring.yahoo.sample.config.InMemoryDatabaseConfig.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("spring-social-yahoo-sample"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }
From source file:com.vmware.entertainmentetc.config.MainConfig.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("entertainmentetc"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }
From source file:com.kdubb.social.config.MainConfig.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("spring-social-quickstart"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }
From source file:p2v.config.MainConfig.java
@Bean(destroyMethod = "shutdown") public DataSource dataSource() { EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory(); factory.setDatabaseName("p2v-spring-social"); factory.setDatabaseType(EmbeddedDatabaseType.H2); factory.setDatabasePopulator(databasePopulator()); return factory.getDatabase(); }