|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2011 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.jdbc.config;
|
18 | 18 |
|
19 |
| -import org.w3c.dom.Element; |
20 |
| - |
21 | 19 | import org.springframework.beans.factory.config.BeanDefinition;
|
22 | 20 | import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
23 | 21 | import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
27 | 25 | import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
28 | 26 | import org.springframework.util.StringUtils;
|
29 | 27 |
|
| 28 | +import org.w3c.dom.Element; |
| 29 | + |
30 | 30 | /**
|
31 |
| - * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses an {@code embedded-database} |
32 |
| - * element and creates a {@link BeanDefinition} for {@link EmbeddedDatabaseFactoryBean}. Picks up nested |
33 |
| - * {@code script} elements and configures a {@link ResourceDatabasePopulator} for them. |
| 31 | + * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that |
| 32 | + * parses an {@code embedded-database} element and creates a {@link BeanDefinition} |
| 33 | + * for an {@link EmbeddedDatabaseFactoryBean}. |
| 34 | + * |
| 35 | + * <p>Picks up nested {@code script} elements and configures a |
| 36 | + * {@link ResourceDatabasePopulator} for each of them. |
34 | 37 | *
|
35 | 38 | * @author Oliver Gierke
|
36 | 39 | * @author Juergen Hoeller
|
| 40 | + * @author Sam Brannen |
37 | 41 | * @since 3.0
|
| 42 | + * @see DatabasePopulatorConfigUtils |
38 | 43 | */
|
39 | 44 | class EmbeddedDatabaseBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
40 | 45 |
|
41 | 46 | @Override
|
42 | 47 | protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
43 | 48 | BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(EmbeddedDatabaseFactoryBean.class);
|
| 49 | + useIdAsDatabaseNameIfGiven(element, builder); |
44 | 50 | setDatabaseType(element, builder);
|
45 | 51 | DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder);
|
46 |
| - useIdAsDatabaseNameIfGiven(element, builder); |
47 | 52 | builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
|
48 | 53 | return builder.getBeanDefinition();
|
49 | 54 | }
|
50 | 55 |
|
| 56 | + @Override |
| 57 | + protected boolean shouldGenerateIdAsFallback() { |
| 58 | + return true; |
| 59 | + } |
| 60 | + |
51 | 61 | private void useIdAsDatabaseNameIfGiven(Element element, BeanDefinitionBuilder builder) {
|
52 | 62 | String id = element.getAttribute(ID_ATTRIBUTE);
|
53 | 63 | if (StringUtils.hasText(id)) {
|
|
0 commit comments