org.springframework.boot.jdbc.EmbeddedDatabaseConnection Java Examples

The following examples show how to use org.springframework.boot.jdbc.EmbeddedDatabaseConnection. 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: DatabaseResourceReleaser.java    From multitenant with 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 File: DataSourceServiceImpl.java    From multitenant with 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
Source File: HibernateDefaultDdlAutoProvider.java    From multitenant with Apache License 2.0 5 votes vote down vote up
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";

}