DATACASS-705 - Polishing.
Use consistently -ref. Original pull request: #167.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import static org.springframework.data.cassandra.config.ParsingUtils.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
@@ -36,8 +38,8 @@ import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses an {@code initialize-keyspace} element
|
||||
* and creates a {@link BeanDefinition} of type {@link DataSourceInitializer}. Picks up nested {@code script} elements
|
||||
* and configures a {@link ResourceKeyspacePopulator} for them.
|
||||
* and creates a {@link BeanDefinition} of type {@link SessionFactoryInitializer}. Picks up nested {@code script}
|
||||
* elements and configures a {@link ResourceKeyspacePopulator} for them.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 3.0
|
||||
@@ -48,7 +50,11 @@ class InitializeKeyspaceBeanDefinitionParser extends AbstractBeanDefinitionParse
|
||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SessionFactoryInitializer.class);
|
||||
builder.addPropertyReference("sessionFactory", element.getAttribute("session-factory"));
|
||||
|
||||
if (element.hasAttribute("session-factory-ref")) {
|
||||
addRequiredPropertyReference(builder, "session", element, "session-factory-ref");
|
||||
}
|
||||
|
||||
builder.addPropertyValue("enabled", element.getAttribute("enabled"));
|
||||
|
||||
parseKeyspacePopulator(element, builder);
|
||||
@@ -64,7 +70,9 @@ class InitializeKeyspaceBeanDefinitionParser extends AbstractBeanDefinitionParse
|
||||
}
|
||||
|
||||
public static void parseKeyspacePopulator(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
List<Element> scripts = DomUtils.getChildElementsByTagName(element, "script");
|
||||
|
||||
if (!scripts.isEmpty()) {
|
||||
builder.addPropertyValue("keyspacePopulator", createKeyspacePopulator(element, scripts, "INIT"));
|
||||
builder.addPropertyValue("keyspaceCleaner", createKeyspacePopulator(element, scripts, "DESTROY"));
|
||||
|
||||
@@ -627,7 +627,7 @@ If you want to initialize a database and you can provide a reference to a `Sessi
|
||||
====
|
||||
[source,xml,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
<cassandra:initialize-keyspace session-factory="sessionFactory">
|
||||
<cassandra:initialize-keyspace session-factory-ref="sessionFactory">
|
||||
<cassandra:script location="classpath:com/foo/cql/db-schema.cql"/>
|
||||
<cassandra:script location="classpath:com/foo/cql/db-test-data.cql"/>
|
||||
</cassandra:initialize-keyspace>
|
||||
@@ -652,7 +652,7 @@ The following example gets a value from a system property:
|
||||
====
|
||||
[source,xml,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
<cassandra:initialize-keyspace session-factory="sessionFactory"
|
||||
<cassandra:initialize-keyspace session-factory-ref="sessionFactory"
|
||||
enabled="#{systemProperties.INITIALIZE_KEYSPACE}"> <1>
|
||||
<cassandra:script location="..."/>
|
||||
</cassandra:initialize-database>
|
||||
@@ -667,7 +667,7 @@ To this end, you can control the ability of the initializer to ignore certain er
|
||||
====
|
||||
[source,xml,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
<cassandra:initialize-keyspace session-factory="sessionFactory" ignore-failures="DROPS">
|
||||
<cassandra:initialize-keyspace session-factory-ref="sessionFactory" ignore-failures="DROPS">
|
||||
<cassandra:script location="..."/>
|
||||
</cassandra:initialize-database>
|
||||
----
|
||||
@@ -686,7 +686,7 @@ You can control that globally or script by script, as the following example show
|
||||
====
|
||||
[source,xml,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
<cassandra:initialize-keyspace session-factory="sessionFactory" separator="@@"> <1>
|
||||
<cassandra:initialize-keyspace session-factory-ref="sessionFactory" separator="@@"> <1>
|
||||
<cassandra:script location="classpath:com/myapp/cql/db-schema.cql" separator=";"/> <2>
|
||||
<cassandra:script location="classpath:com/myapp/cql/db-test-data-1.cql"/>
|
||||
<cassandra:script location="classpath:com/myapp/cql/db-test-data-2.cql"/>
|
||||
|
||||
Reference in New Issue
Block a user