Java Code Examples for org.springframework.jdbc.datasource.init.ResourceDatabasePopulator#setContinueOnError()

The following examples show how to use org.springframework.jdbc.datasource.init.ResourceDatabasePopulator#setContinueOnError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DruidDataSourceInitializer.java    From druid-spring-boot with Apache License 2.0 7 votes vote down vote up
private void runScripts(DataSource dataSource, List<Resource> resources, String username, String password) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(this.properties.isContinueOnError());
    populator.setSeparator(this.properties.getSeparator());
    if (this.properties.getSqlScriptEncoding() != null) {
        populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
    }
    for (Resource resource : resources) {
        populator.addScript(resource);
    }
    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        dataSource = DataSourceBuilder.create(this.properties.getClassLoader())
                .driverClassName(this.properties.determineDriverClassName())
                .url(this.properties.determineUrl())
                .username(username)
                .password(password)
                .build();
    }
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 2
Source File: HsqlDatabaseBuilder.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public DataSource toDataSource() {
  DataSource dataSource;

  if (url == null || url.contains("hsqldb:mem")) {
    log.debug("Creating in memory HSQL database");
    // Start an in-process, in-memory HSQL server
    dataSource = new EmbeddedDatabaseBuilder().setType(HSQL).setName("c2mondb").build();
  } else {
    log.debug("Creating HSQL database at URL {}",url);
    dataSource = DataSourceBuilder.create().url(url).username(username).password(password).build();
  }

  if (!scripts.isEmpty()) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(scripts.toArray(new Resource[scripts.size()]));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource);
  }

  return dataSource;
}
 
Example 3
Source File: MultiDataSourceInitializer.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
private void runScripts(List<Resource> resources, String username, String password) {
    if (resources.isEmpty()) {
        return;
    }
    boolean continueOnError = Boolean.parseBoolean(getProperty("continue-on-error"));
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(continueOnError);
    populator.setSeparator(getProperty("seperator"));

    if (getProperty("sql-script-encoding") != null) {
        populator.setSqlScriptEncoding(getProperty("sql-script-encoding"));
    }
    for (Resource resource : resources) {
        populator.addScript(resource);
    }
    DataSource dataSource = this.dataSource;
    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        String driver = getProperty("driver-class-name");
        String url = getProperty("url");
        dataSource = DataSourceBuilder.create(this.getClass().getClassLoader()).driverClassName(driver).url(url)
                .username(username).password(password).build();
    }
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 4
Source File: DatabaseBasedTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void executeSqlScripts(List<Resource> scipts) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    scipts.forEach(populator::addScript);
    populator.execute(dataSource);
}
 
Example 5
Source File: DataflowRdbmsInitializer.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if (dataSource != null && definitionInitializationEnable) {
		String platform = getDatabaseType(dataSource);
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = schema;
		schemaLocation = schemaLocation.replace("@@platform@@", platform);
		String commonSchemaLocation = schemaLocation;
		commonSchemaLocation = commonSchemaLocation.replace("@@suffix@@", COMMON_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", commonSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(commonSchemaLocation));

		String applicationssSchemaLocation = schemaLocation;
		applicationssSchemaLocation = applicationssSchemaLocation.replace("@@suffix@@", APPLICATIONS_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", applicationssSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(applicationssSchemaLocation));

		String deploymentSchemaLocation = schemaLocation;
		deploymentSchemaLocation = deploymentSchemaLocation.replace("@@suffix@@", DEPLOYMENT_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", deploymentSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(deploymentSchemaLocation));

		populator.setContinueOnError(true);
		logger.debug(String.format("Initializing dataflow schema for %s database", platform));
		DatabasePopulatorUtils.execute(populator, dataSource);
	}
}
 
Example 6
Source File: TestDatabase.java    From we-cmdb with Apache License 2.0 5 votes vote down vote up
static public void prepareDatabase(DataSource dataSource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    populator.addScript(new ClassPathResource("/db/data_model.sql"));
    populator.execute(dataSource);
}
 
Example 7
Source File: SystemVariableServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void executeSqlScripts(List<Resource> scipts) throws ScriptException {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    scipts.forEach(populator::addScript);
    populator.execute(dataSource);
}
 
Example 8
Source File: PluginInstanceServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void executeSqlScripts(List<Resource> scipts) throws ScriptException {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    scipts.forEach(populator::addScript);
    populator.execute(dataSource);
}
 
Example 9
Source File: MasterDomain.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Bean(name = "MasterResourceDatabasePopulator")
@ConditionalOnMissingBean(name = "MasterResourceDatabasePopulator")
public ResourceDatabasePopulator masterResourceDatabasePopulator() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(true);
    databasePopulator.setIgnoreFailedDrops(true);
    databasePopulator.setSqlScriptEncoding("UTF-8");
    databasePopulator.addScript(auditSql);
    return databasePopulator;
}
 
Example 10
Source File: PluginInstanceService.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void initMysqlDatabaseTables(ResourceServer dbServer, PluginMysqlInstance mysqlInstance,
        PluginPackage pluginPackage) {

    String tmpFolderName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
    String initSqlPath = SystemUtils.getTempFolderPath() + tmpFolderName + "/" + pluginProperties.getInitDbSql();

    String s3KeyName = pluginPackage.getName() + File.separator + pluginPackage.getVersion() + File.separator
            + pluginProperties.getInitDbSql();
    logger.info("Download init.sql from S3: {}", s3KeyName);

    s3Client.downFile(pluginProperties.getPluginPackageBucketName(), s3KeyName, initSqlPath);

    DriverManagerDataSource dataSource = new DriverManagerDataSource(
            "jdbc:mysql://" + dbServer.getHost() + ":" + dbServer.getPort() + "/" + mysqlInstance.getSchemaName()
                    + "?characterEncoding=utf8&serverTimezone=UTC",
            mysqlInstance.getUsername(), EncryptionUtils.decryptWithAes(mysqlInstance.getPassword(),
                    resourceProperties.getPasswordEncryptionSeed(), mysqlInstance.getSchemaName()));
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
    File initSqlFile = new File(initSqlPath);
    List<Resource> scipts = newArrayList(new FileSystemResource(initSqlFile));
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    scipts.forEach(populator::addScript);
    try {
        populator.execute(dataSource);
    } catch (Exception e) {
        String errorMessage = String.format("Failed to execute init.sql for schema[%s]",
                mysqlInstance.getSchemaName());
        logger.error(errorMessage);
        throw new WecubeCoreException(errorMessage, e);
    }
    logger.info(String.format("Init database[%s] tables has done..", mysqlInstance.getSchemaName()));
}
 
Example 11
Source File: TaskRepositoryInitializer.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	boolean isInitializeEnabled = (this.taskProperties.isInitializeEnabled() != null)
			? this.taskProperties.isInitializeEnabled()
			: this.taskInitializationEnabled;
	if (this.dataSource != null && isInitializeEnabled && this.taskProperties
			.getTablePrefix().equals(TaskProperties.DEFAULT_TABLE_PREFIX)) {
		String platform = getDatabaseType(this.dataSource);
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		if ("mysql".equals(platform)) {
			platform = "mysql";
		}
		if ("sqlserver".equals(platform)) {
			platform = "sqlserver";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = schema;
		schemaLocation = schemaLocation.replace("@@platform@@", platform);
		populator.addScript(this.resourceLoader.getResource(schemaLocation));
		populator.setContinueOnError(true);
		logger.debug(
				String.format("Initializing task schema for %s database", platform));
		DatabasePopulatorUtils.execute(populator, this.dataSource);
	}
}
 
Example 12
Source File: ProvisioningContext.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Bean
public SchedulerDBInit quartzDataSourceInit() {
    SchedulerDBInit init = new SchedulerDBInit();
    init.setDataSource(masterDataSource);

    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(true);
    databasePopulator.setIgnoreFailedDrops(true);
    databasePopulator.setSqlScriptEncoding(StandardCharsets.UTF_8.name());
    databasePopulator.setScripts(new ClassPathResource("/quartz/" + env.getProperty("quartz.sql")));
    init.setDatabasePopulator(databasePopulator);

    return init;
}
 
Example 13
Source File: TestDatabase.java    From we-cmdb with Apache License 2.0 5 votes vote down vote up
static public void cleanUpDatabase(DataSource dataSource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    populator.addScript(new ClassPathResource("/db/drop.all.sql"));
    populator.execute(dataSource);
}
 
Example 14
Source File: TestDatabase.java    From we-cmdb with Apache License 2.0 5 votes vote down vote up
static public void prepareDatabaseOfLegacyModel(DataSource dataSource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    populator.addScript(new ClassPathResource("/db/legacy/1.init.schema.sql"));
    populator.addScript(new ClassPathResource("/db/legacy/2.init.static.data.sys.sql"));
    populator.addScript(new ClassPathResource("/db/legacy/3.init.static.data.ci.sql"));
    populator.addScript(new ClassPathResource("/db/legacy/4.init.data.ci.sql"));
    populator.execute(dataSource);
}
 
Example 15
Source File: PluginInstanceService.java    From wecube-platform with Apache License 2.0 4 votes vote down vote up
private void performUpgradeMysqlDatabaseData(PluginMysqlInstance mysqlInstance, PluginPackage pluginPackage,
        String latestVersion) throws IOException {
    String tmpFolderName = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
    String baseTmpDir = SystemUtils.getTempFolderPath() + tmpFolderName + "/";
    String initSqlPath = baseTmpDir + pluginProperties.getInitDbSql();

    String s3KeyName = pluginPackage.getName() + File.separator + pluginPackage.getVersion() + File.separator
            + pluginProperties.getInitDbSql();
    logger.info("Download init.sql from S3: {}", s3KeyName);

    s3Client.downFile(pluginProperties.getPluginPackageBucketName(), s3KeyName, initSqlPath);

    ResourceServer dbServer = resourceItemRepository.findById(mysqlInstance.getResourceItemId()).get()
            .getResourceServer();
    DriverManagerDataSource dataSource = new DriverManagerDataSource(
            "jdbc:mysql://" + dbServer.getHost() + ":" + dbServer.getPort() + "/" + mysqlInstance.getSchemaName()
                    + "?characterEncoding=utf8&serverTimezone=UTC",
            mysqlInstance.getUsername(), EncryptionUtils.decryptWithAes(mysqlInstance.getPassword(),
                    resourceProperties.getPasswordEncryptionSeed(), mysqlInstance.getSchemaName()));
    dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");

    File initSqlFile = new File(initSqlPath);

    File upgradeSqlFile = parseUpgradeMysqlDataFile(baseTmpDir, initSqlFile, pluginPackage, latestVersion);
    List<Resource> scripts = newArrayList(new FileSystemResource(upgradeSqlFile));
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(false);
    populator.setIgnoreFailedDrops(false);
    populator.setSeparator(";");
    populator.setCommentPrefix("#");
    populator.setSqlScriptEncoding("utf-8");
    for(Resource script : scripts) {
    	populator.addScript(script);
    }
    try {
    	logger.info("start to execute sql script file:{}, host:{},port:{},schema:{}", 
    			upgradeSqlFile.getAbsolutePath(),
    			dbServer.getHost(),
    			dbServer.getPort(),
    			mysqlInstance.getSchemaName());
        populator.execute(dataSource);
    } catch (Exception e) {
        String errorMessage = String.format("Failed to execute [{}] for schema[%s]",
        		upgradeSqlFile.getName(), mysqlInstance.getSchemaName());
        logger.error(errorMessage);
        throw new WecubeCoreException(errorMessage, e);
    }
    logger.info(String.format("Upgrade database[%s] finished...", mysqlInstance.getSchemaName()));
}
 
Example 16
Source File: SqlScriptsTestExecutionListener.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Execute the SQL scripts configured via the supplied {@link Sql @Sql}
 * annotation for the given {@link ExecutionPhase} and {@link TestContext}.
 * <p>Special care must be taken in order to properly support the configured
 * {@link SqlConfig#transactionMode}.
 * @param sql the {@code @Sql} annotation to parse
 * @param executionPhase the current execution phase
 * @param testContext the current {@code TestContext}
 * @param classLevel {@code true} if {@link Sql @Sql} was declared at the class level
 */
private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestContext testContext, boolean classLevel)
		throws Exception {

	if (executionPhase != sql.executionPhase()) {
		return;
	}

	MergedSqlConfig mergedSqlConfig = new MergedSqlConfig(sql.config(), testContext.getTestClass());
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Processing %s for execution phase [%s] and test context %s.",
				mergedSqlConfig, executionPhase, testContext));
	}

	final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setSqlScriptEncoding(mergedSqlConfig.getEncoding());
	populator.setSeparator(mergedSqlConfig.getSeparator());
	populator.setCommentPrefix(mergedSqlConfig.getCommentPrefix());
	populator.setBlockCommentStartDelimiter(mergedSqlConfig.getBlockCommentStartDelimiter());
	populator.setBlockCommentEndDelimiter(mergedSqlConfig.getBlockCommentEndDelimiter());
	populator.setContinueOnError(mergedSqlConfig.getErrorMode() == ErrorMode.CONTINUE_ON_ERROR);
	populator.setIgnoreFailedDrops(mergedSqlConfig.getErrorMode() == ErrorMode.IGNORE_FAILED_DROPS);

	String[] scripts = getScripts(sql, testContext, classLevel);
	scripts = TestContextResourceUtils.convertToClasspathResourcePaths(testContext.getTestClass(), scripts);
	List<Resource> scriptResources = TestContextResourceUtils.convertToResourceList(
			testContext.getApplicationContext(), scripts);
	for (String stmt : sql.statements()) {
		if (StringUtils.hasText(stmt)) {
			stmt = stmt.trim();
			scriptResources.add(new ByteArrayResource(stmt.getBytes(), "from inlined SQL statement: " + stmt));
		}
	}
	populator.setScripts(scriptResources.toArray(new Resource[0]));
	if (logger.isDebugEnabled()) {
		logger.debug("Executing SQL scripts: " + ObjectUtils.nullSafeToString(scriptResources));
	}

	String dsName = mergedSqlConfig.getDataSource();
	String tmName = mergedSqlConfig.getTransactionManager();
	DataSource dataSource = TestContextTransactionUtils.retrieveDataSource(testContext, dsName);
	PlatformTransactionManager txMgr = TestContextTransactionUtils.retrieveTransactionManager(testContext, tmName);
	boolean newTxRequired = (mergedSqlConfig.getTransactionMode() == TransactionMode.ISOLATED);

	if (txMgr == null) {
		Assert.state(!newTxRequired, () -> String.format("Failed to execute SQL scripts for test context %s: " +
				"cannot execute SQL scripts using Transaction Mode " +
				"[%s] without a PlatformTransactionManager.", testContext, TransactionMode.ISOLATED));
		Assert.state(dataSource != null, () -> String.format("Failed to execute SQL scripts for test context %s: " +
				"supply at least a DataSource or PlatformTransactionManager.", testContext));
		// Execute scripts directly against the DataSource
		populator.execute(dataSource);
	}
	else {
		DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(txMgr);
		// Ensure user configured an appropriate DataSource/TransactionManager pair.
		if (dataSource != null && dataSourceFromTxMgr != null && !dataSource.equals(dataSourceFromTxMgr)) {
			throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: " +
					"the configured DataSource [%s] (named '%s') is not the one associated with " +
					"transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
					dsName, txMgr.getClass().getName(), tmName));
		}
		if (dataSource == null) {
			dataSource = dataSourceFromTxMgr;
			Assert.state(dataSource != null, () -> String.format("Failed to execute SQL scripts for " +
					"test context %s: could not obtain DataSource from transaction manager [%s] (named '%s').",
					testContext, txMgr.getClass().getName(), tmName));
		}
		final DataSource finalDataSource = dataSource;
		int propagation = (newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW :
				TransactionDefinition.PROPAGATION_REQUIRED);
		TransactionAttribute txAttr = TestContextTransactionUtils.createDelegatingTransactionAttribute(
				testContext, new DefaultTransactionAttribute(propagation));
		new TransactionTemplate(txMgr, txAttr).execute(status -> {
			populator.execute(finalDataSource);
			return null;
		});
	}
}
 
Example 17
Source File: DomainConfFactory.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public void register(final Domain domain) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName(domain.getJdbcDriver());
    hikariConfig.setJdbcUrl(domain.getJdbcURL());
    hikariConfig.setUsername(domain.getDbUsername());
    hikariConfig.setPassword(domain.getDbPassword());
    hikariConfig.setSchema(domain.getDbSchema());
    hikariConfig.setTransactionIsolation(domain.getTransactionIsolation().name());
    hikariConfig.setMaximumPoolSize(domain.getPoolMaxActive());
    hikariConfig.setMinimumIdle(domain.getPoolMinIdle());

    // domainDataSource
    registerBeanDefinition(
            domain.getKey() + "DataSource",
            BeanDefinitionBuilder.rootBeanDefinition(JndiObjectFactoryBean.class).
                    addPropertyValue("jndiName", "java:comp/env/jdbc/syncope" + domain.getKey() + "DataSource").
                    addPropertyValue("defaultObject", new HikariDataSource(hikariConfig)).
                    getBeanDefinition());
    DataSource initedDataSource = ApplicationContextProvider.getBeanFactory().
            getBean(domain.getKey() + "DataSource", DataSource.class);

    // domainResourceDatabasePopulator
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(true);
    databasePopulator.setIgnoreFailedDrops(true);
    databasePopulator.setSqlScriptEncoding(StandardCharsets.UTF_8.name());
    databasePopulator.addScript(new ClassPathResource("/audit/" + domain.getAuditSql()));
    registerSingleton(domain.getKey().toLowerCase() + "ResourceDatabasePopulator", databasePopulator);

    // domainDataSourceInitializer
    DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
    dataSourceInitializer.setDataSource(initedDataSource);
    dataSourceInitializer.setEnabled(true);
    dataSourceInitializer.setDatabasePopulator(databasePopulator);
    registerSingleton(domain.getKey().toLowerCase() + "DataSourceInitializer", dataSourceInitializer);

    // domainEntityManagerFactory
    OpenJpaVendorAdapter vendorAdapter = new OpenJpaVendorAdapter();
    vendorAdapter.setShowSql(false);
    vendorAdapter.setGenerateDdl(true);
    vendorAdapter.setDatabasePlatform(domain.getDatabasePlatform());

    BeanDefinitionBuilder emf = BeanDefinitionBuilder.rootBeanDefinition(DomainEntityManagerFactoryBean.class).
            addPropertyValue("mappingResources", domain.getOrm()).
            addPropertyValue("persistenceUnitName", domain.getKey()).
            addPropertyReference("dataSource", domain.getKey() + "DataSource").
            addPropertyValue("jpaVendorAdapter", vendorAdapter).
            addPropertyReference("commonEntityManagerFactoryConf", "commonEMFConf");
    if (env.containsProperty("openjpaMetaDataFactory")) {
        emf.addPropertyValue("jpaPropertyMap", Map.of(
                "openjpa.MetaDataFactory",
                Objects.requireNonNull(env.getProperty("openjpaMetaDataFactory")).
                        replace("##orm##", domain.getOrm())));
    }
    registerBeanDefinition(domain.getKey() + "EntityManagerFactory", emf.getBeanDefinition());
    ApplicationContextProvider.getBeanFactory().getBean(domain.getKey() + "EntityManagerFactory");

    // domainTransactionManager
    AbstractBeanDefinition domainTransactionManager =
            BeanDefinitionBuilder.rootBeanDefinition(JpaTransactionManager.class).
                    addPropertyReference("entityManagerFactory", domain.getKey() + "EntityManagerFactory").
                    getBeanDefinition();
    domainTransactionManager.addQualifier(new AutowireCandidateQualifier(Qualifier.class, domain.getKey()));
    registerBeanDefinition(domain.getKey() + "TransactionManager", domainTransactionManager);

    // domainContentXML
    registerBeanDefinition(domain.getKey() + "ContentXML",
            BeanDefinitionBuilder.rootBeanDefinition(ByteArrayInputStream.class).
                    addConstructorArgValue(domain.getContent().getBytes()).
                    getBeanDefinition());

    // domainKeymasterConfParamsJSON
    registerBeanDefinition(domain.getKey() + "KeymasterConfParamsJSON",
            BeanDefinitionBuilder.rootBeanDefinition(ByteArrayInputStream.class).
                    addConstructorArgValue(domain.getKeymasterConfParams().getBytes()).
                    getBeanDefinition());
}
 
Example 18
Source File: SocialDatabasePopulator.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
private void runScript(final Resource resource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(true);
    populator.addScript(resource);
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 19
Source File: SocialDatabasePopulator.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
private void runScript(final Resource resource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(true);
    populator.addScript(resource);
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 20
Source File: DatabaseInitializer.java    From lemonaid with MIT License 4 votes vote down vote up
private void runScript(Resource resource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(true);
    populator.addScript(resource);
    DatabasePopulatorUtils.execute(populator, dataSource);
}