DATACASS-162: xml parser now reading entity-base-packages attribute
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
|
||||
import org.springframework.data.cassandra.config.DefaultBeanNames;
|
||||
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.EntityMapping;
|
||||
@@ -64,6 +65,18 @@ public class CassandraMappingContextParser extends AbstractSingleBeanDefinitionP
|
||||
|
||||
protected void parseMapping(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
String packages = element.getAttribute("entity-base-packages");
|
||||
if (StringUtils.hasText(packages)) {
|
||||
try {
|
||||
Set<Class<?>> entityClasses = CassandraEntityClassScanner.scan(StringUtils
|
||||
.commaDelimitedListToStringArray(packages));
|
||||
builder.addPropertyValue("initialEntitySet", entityClasses);
|
||||
} catch (Exception x) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"encountered exception while scanning for entity classes in package(s) [%s]", packages), x);
|
||||
}
|
||||
}
|
||||
|
||||
Set<EntityMapping> mappings = new HashSet<EntityMapping>();
|
||||
|
||||
for (Element entity : DomUtils.getChildElementsByTagName(element, "entity")) {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.xmlentityscanning;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class AnotherScannedEntity {
|
||||
|
||||
/*
|
||||
* Primary Row ID
|
||||
*/
|
||||
@Id private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private AnotherScannedEntity() {}
|
||||
|
||||
public AnotherScannedEntity(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AnotherScannedEntity other = (AnotherScannedEntity) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.xmlentityscanning;
|
||||
|
||||
import org.springframework.data.cassandra.repository.TypedIdCassandraRepository;
|
||||
|
||||
public interface AnotherScannedEntityRepository extends TypedIdCassandraRepository<AnotherScannedEntity, String> {}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.xmlentityscanning;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
@Table
|
||||
public class ScannedEntity {
|
||||
|
||||
/*
|
||||
* Primary Row ID
|
||||
*/
|
||||
@Id private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ScannedEntity() {}
|
||||
|
||||
public ScannedEntity(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ScannedEntity other = (ScannedEntity) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.xmlentityscanning;
|
||||
|
||||
import org.springframework.data.cassandra.repository.TypedIdCassandraRepository;
|
||||
|
||||
public interface ScannedEntityRepository extends TypedIdCassandraRepository<ScannedEntity, String> {}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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.data.cassandra.test.integration.xmlentityscanning;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class XmlEntityScanningIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Autowired ScannedEntityRepository repository;
|
||||
@Autowired AnotherScannedEntityRepository anotherRepository;
|
||||
|
||||
@Autowired CassandraOperations template;
|
||||
|
||||
@Test
|
||||
public void testInsertScannedEntity() {
|
||||
repository.save(new ScannedEntity("one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertAnotherScannedEntity() {
|
||||
anotherRepository.save(new AnotherScannedEntity("another"));
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,12 @@
|
||||
</cass:mapping>
|
||||
|
||||
<cass:cluster port="${cassandra.native_transport_port}">
|
||||
<cass:keyspace name="UserRepositoryXmlConfigIntegrationTests"
|
||||
<cass:keyspace name="#{randomKeyspaceName}"
|
||||
action="CREATE" durable-writes="true">
|
||||
</cass:keyspace>
|
||||
</cass:cluster>
|
||||
|
||||
<cass:session keyspace-name="UserRepositoryXmlConfigIntegrationTests"
|
||||
<cass:session keyspace-name="#{randomKeyspaceName}"
|
||||
schema-action="CREATE">
|
||||
</cass:session>
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cass="http://www.springframework.org/schema/data/cassandra"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/data/cassandra http://www.springframework.org/schema/data/cassandra/spring-cassandra-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
|
||||
">
|
||||
|
||||
<import resource="classpath:/spring-data-cassandra-basic.xml" />
|
||||
|
||||
<cass:mapping
|
||||
entity-base-packages="org.springframework.data.cassandra.test.integration.xmlentityscanning" />
|
||||
|
||||
<cass:cluster port="${cassandra.native_transport_port}">
|
||||
<cass:keyspace name="#{randomKeyspaceName}"
|
||||
action="CREATE" durable-writes="true">
|
||||
</cass:keyspace>
|
||||
</cass:cluster>
|
||||
|
||||
<cass:session keyspace-name="#{randomKeyspaceName}"
|
||||
schema-action="CREATE">
|
||||
</cass:session>
|
||||
|
||||
<cass:repositories
|
||||
base-package="org.springframework.data.cassandra.test.integration.xmlentityscanning" />
|
||||
</beans>
|
||||
Reference in New Issue
Block a user