forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
186 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...va/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2012-2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.autoconfigure.jdbc; | ||
|
||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.beans.factory.support.GenericBeanDefinition; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
|
||
/** | ||
* Configures DataSource initialization. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
@Configuration | ||
@Import({ DataSourceInitializationConfiguration.Registrar.class, | ||
DataSourceInitializerInvoker.class }) | ||
class DataSourceInitializationConfiguration { | ||
|
||
|
||
/** | ||
* {@link ImportBeanDefinitionRegistrar} to register the | ||
* {@link DataSourceInitializerPostProcessor} without causing early bean instantiation | ||
* issues. | ||
*/ | ||
static class Registrar implements ImportBeanDefinitionRegistrar { | ||
|
||
private static final String BEAN_NAME = "dataSourceInitializerPostProcessor"; | ||
|
||
@Override | ||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, | ||
BeanDefinitionRegistry registry) { | ||
if (!registry.containsBeanDefinition(BEAN_NAME)) { | ||
GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); | ||
beanDefinition.setBeanClass(DataSourceInitializerPostProcessor.class); | ||
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); | ||
// We don't need this one to be post processed otherwise it can cause a | ||
// cascade of bean instantiation that we would rather avoid. | ||
beanDefinition.setSynthetic(true); | ||
registry.registerBeanDefinition(BEAN_NAME, beanDefinition); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
43 changes: 0 additions & 43 deletions
43
...src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializedEvent.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...c/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2012-2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.autoconfigure.jdbc; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.beans.factory.SmartInitializingSingleton; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
/** | ||
* Bean to handle {@link DataSource} initialization by running {@literal schema-*.sql} on | ||
* {@link InitializingBean#afterPropertiesSet()} and {@literal data-*.sql} SQL scripts on | ||
* a {@link SmartInitializingSingleton#afterSingletonsInstantiated()}. | ||
* | ||
* @author Dave Syer | ||
* @author Phillip Webb | ||
* @author Eddú Meléndez | ||
* @author Stephane Nicoll | ||
* @author Kazuki Shimizu | ||
* @since 1.1.0 | ||
* @see DataSourceAutoConfiguration | ||
*/ | ||
class DataSourceInitializerInvoker implements InitializingBean { | ||
|
||
private final DataSourceInitializer dataSourceInitializer; | ||
|
||
DataSourceInitializerInvoker(ObjectProvider<DataSource> dataSource, | ||
DataSourceProperties properties, | ||
ApplicationContext applicationContext) { | ||
DataSource ds = dataSource.getIfAvailable(); | ||
this.dataSourceInitializer = ds != null | ||
? new DataSourceInitializer(ds, properties, applicationContext) : null; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
if (this.dataSourceInitializer != null) { | ||
this.dataSourceInitializer.createSchema(); | ||
this.dataSourceInitializer.initSchema(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.