List of usage examples for org.springframework.jdbc.datasource.init ResourceDatabasePopulator ResourceDatabasePopulator
public ResourceDatabasePopulator(Resource... scripts)
From source file:cz.muni.fi.pv168.project.hotelmanager.Main.java
public static DataSource createMemoryDatabase() { log.info("starts creation of tables"); BasicDataSource bds = new BasicDataSource(); //set JDBC driver and URL bds.setDriverClassName(EmbeddedDriver.class.getName()); log.info("try create Datasource"); bds.setUrl("jdbc:derby:memory:HotelManagerDB;create=true"); //populate db with tables and data log.info("try create tables"); new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds); log.info("return datasource"); return bds;/*from ww w. jav a 2 s.co m*/ }
From source file:cz.muni.fi.pv168.project.hotelmanager.RoomManagerImplTest.java
@Before public void setUp() throws SQLException { BasicDataSource bds = new BasicDataSource(); //set JDBC driver and URL bds.setDriverClassName(EmbeddedDriver.class.getName()); bds.setUrl("jdbc:derby:memory:TestRoomManagerDB;create=true"); //populate db with tables and data new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds); this.dataSource = bds; manager = new RoomManagerImpl(bds); }
From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.java
@Before public void setUp() throws SQLException { BasicDataSource bds = new BasicDataSource(); //set JDBC driver and URL bds.setDriverClassName(EmbeddedDriver.class.getName()); bds.setUrl("jdbc:derby:memory:TestReservationManagerDB;create=true"); this.dataSource = bds; //populate db with tables and data new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds); guestManager = new GuestManagerImpl(bds); roomManager = new RoomManagerImpl(bds); reservationManager = new ReservationManagerImpl(prepareClockMock(now), bds); }
From source file:com.springsource.open.db.AtomikosApplication.java
private DataSourceInitializer initialize(DataSource dataSource, String name) { DataSourceInitializer initializer = new DataSourceInitializer(); initializer.setDataSource(dataSource); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(new ClassPathResource(name + ".sql")); populator.setIgnoreFailedDrops(true); initializer.setDatabasePopulator(populator); return initializer; }
From source file:com.github.mrstampy.gameboot.data.GameBootDataConfiguration.java
/** * File database populator.//from ww w . ja v a 2 s .c o m * * @return the resource database populator * @throws Exception * the exception */ @Bean @Conditional(FileCondition.class) public ResourceDatabasePopulator fileDatabasePopulator() throws Exception { return new ResourceDatabasePopulator(ctx.getResource(FileCondition.GAMEBOOT_SQL)); }
From source file:com.github.mrstampy.gameboot.data.GameBootDataConfiguration.java
/** * Ext class path database populator./*from w ww . j a v a 2 s .c o m*/ * * @return the resource database populator * @throws Exception * the exception */ @Bean @Conditional(ExternalClassPathCondition.class) public ResourceDatabasePopulator extClassPathDatabasePopulator() throws Exception { return new ResourceDatabasePopulator(ctx.getResource(ExternalClassPathCondition.GAMEBOOT_SQL)); }
From source file:com.github.mrstampy.gameboot.data.GameBootDataConfiguration.java
/** * Classpath database populator./* w ww. ja va2 s .co m*/ * * @return the resource database populator * @throws Exception * the exception */ @Bean @Conditional(ClassPathCondition.class) public ResourceDatabasePopulator classpathDatabasePopulator() throws Exception { return new ResourceDatabasePopulator(ctx.getResource(ClassPathCondition.GAMEBOOT_SQL)); }
From source file:org.zalando.stups.junit.postgres.PostgreSqlRule.java
private void applyScripts(PostgresConfig config) throws SQLException, IOException { log.info("Apply Scripts ..."); Connection connection = getConnection(config); DataSource ds = new SingleConnectionDataSource(connection, false); FileSystemScanner scanner = new FileSystemScanner(); for (String location : builder.locations) { File directory = new File(location); if (directory.exists() && directory.isDirectory()) { Resource[] resources = scanner.scanForResources(location, "", ".sql"); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resources); populator.setSeparator(builder.separator); populator.execute(ds);//from w w w.j a va 2 s . c om } else { // log not existing directory } } log.info("Scripts applied!"); }
From source file:org.apache.syncope.client.cli.commands.MigrateTest.java
@Test public void conf() throws Exception { // 1. migrate String[] args = new String[4]; args[0] = "migrate"; args[1] = "--conf"; args[2] = BASE_PATH + File.separator + "content12.xml"; args[3] = BASE_PATH + File.separator + "MasterContent.xml"; new MigrateCommand().execute(new Input(args)); // 2. initialize db as persistence-jpa does DataSource dataSource = new DriverManagerDataSource("jdbc:h2:mem:syncopedb;DB_CLOSE_DELAY=-1", "sa", null); new ResourceDatabasePopulator(new ClassPathResource("/schema20.sql")).execute(dataSource); // 3. attempt to set initial content from the migrated MasterContent.xml SAXParserFactory factory = SAXParserFactory.newInstance(); InputStream in = null;// ww w . j ava 2s .c o m try { in = new FileInputStream(args[3]); SAXParser parser = factory.newSAXParser(); parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false)); } finally { IOUtils.closeQuietly(in); } }