Java Code Examples for org.springframework.boot.jdbc.EmbeddedDatabaseConnection

The following examples show how to use org.springframework.boot.jdbc.EmbeddedDatabaseConnection. These examples are extracted from open source projects. 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 Project: multitenant   Source File: DatabaseResourceReleaser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void release(Organization organization) {
	entityManagerFactoryService.removeEntityManagerFactory(organization);
	EntityManager em = EntityManagerFactoryUtils.getTransactionalEntityManager(emf);
	if (!EmbeddedDatabaseConnection.isEmbedded(properties.determineDriverClassName())) {
		em.createNativeQuery("drop database " + organization.getId()).executeUpdate();
	}
	
}
 
Example 2
Source Project: multitenant   Source File: DataSourceServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public DataSource createDataSource(Organization organization) {
	return MultitenantUtils.doQuery(() -> {
		DataSource dataSouce = null;
		DataSourceInfo dataSourceInfo = dataSourceInfoService.get(organization);
		if (StringUtils.isEmpty(dataSourceInfo.getJndiName())) {
			String master = Constants.MASTER;
			if (EmbeddedDatabaseConnection.isEmbedded(dataSourceInfo.getDriverClassName())) {
				master = properties.determineDatabaseName();
			}
			DataSourceBuilder<?> factory = this.properties.initializeDataSourceBuilder();
			factory.url(dataSourceInfo.getUrl().replace(databaseNameService.getDatabaseName(master), databaseNameService.getDatabaseName(organization.getId())))
				.username(dataSourceInfo.getUsername())
				.password(dataSourceInfo.getPassword());
			if (!StringUtils.isEmpty(dataSourceInfo.getDriverClassName())) {
				factory.driverClassName(dataSourceInfo.getDriverClassName());
			}
			if (!StringUtils.isEmpty(dataSourceInfo.getType())) {
				try {
					factory.type((Class<? extends DataSource>) Class.forName(dataSourceInfo.getType()));
				} catch (ClassNotFoundException e) {
					throw new RuntimeException(e.getMessage());
				}
			}
			publishEvent(organization, dataSourceInfo, factory);
			dataSouce = factory.build();
		} else {
			JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
			dataSouce = dataSourceLookup.getDataSource(dataSourceInfo.getJndiName());
		}
		dataSourceMap.put(organization.getId(), dataSouce);
		this.applicationContext.publishEvent(new OrgDataSourceCreateEvent(dataSouce));
		return dataSouce;
	});

}
 
Example 3
public String getDefaultDdlAuto(DataSource dataSource) {
	if (!EmbeddedDatabaseConnection.isEmbedded(dataSource)) {
		return "none";
	}
	SchemaManagement schemaManagement = getSchemaManagement(dataSource);
	if (SchemaManagement.MANAGED.equals(schemaManagement)) {
		return "none";
	}
	return "create-drop";

}