Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ At the time of writing this is JDK7 (binary compatibility) but at compile time J

## Code Style

A dedicated and holistic code style is not yet defined.
Changes to existing classes should follow the style that is found in that specific class.
Google's Java code style is followed available [here](https://github.com/google/styleguide).

In gernal, the Google Code style should be followed.
The proper formatting is checked during compile time. To easily follow the style use **one** of those options:
1. Use [Eclipse Formatter](https://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-formatter.htm) with the `src/eclipse-java-google-style.xml` file.
1. Use [IntelliJ Formatter](https://blog.jetbrains.com/idea/2014/01/intellij-idea-13-importing-code-formatter-settings-from-eclipse/) with the `src/eclipse-java-google-style.xml` file.
1. Use `mvn formatter:format` to apply the style to the source files.

## Merging

Expand Down
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.7.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down Expand Up @@ -286,6 +291,7 @@
<exclude>src/test/resources/**</exclude>
<exclude>src/main/resources/**</exclude>
<exclude>**/*.psd</exclude>
<exclude>src/eclipse-java-google-style.xml</exclude>
</excludes>
</configuration>
<executions>
Expand Down Expand Up @@ -353,6 +359,20 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<configuration>
<configFile>${project.basedir}/eclipse-formatter-config.xml</configFile>
</configuration>
<executions>
<execution>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<action dev="blx" type="add" date="2018-03-26">
Add support for DynamoDBTypeConverted annotations on hash key
</action>
<action dev="derjust" type="fix" date="">
Fixed NullPointerException for findAllByOrderByProperty queries
</action>
</release>
<release version="5.0.2" date="2018-03-05" description="Maintenance release">
<action dev="vitolimandibhrata" issue="40" type="add" date="2017-01-07">
Expand Down
337 changes: 337 additions & 0 deletions src/eclipse-java-google-style.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,75 +40,83 @@
@Configuration
public abstract class AbstractDynamoDBConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDynamoDBConfiguration.class);

public abstract AmazonDynamoDB amazonDynamoDB();

public abstract AWSCredentials amazonAWSCredentials();

/**
* Return the base packages to scan for mapped {@link DynamoDBTable}s. Will return the package name of the configuration
* class' (the concrete class, not this one here) by default. So if you have a {@code com.acme.AppConfig} extending
* {@link AbstractDynamoDBConfiguration} the base package will be considered {@code com.acme} unless the method is
* overriden to implement alternate behaviour.
*
* @return the base package to scan for mapped {@link DynamoDBTable} classes or {@literal null} to not enable scanning for
* entities.
*/
protected String[] getMappingBasePackages() {

Package mappingBasePackage = getClass().getPackage();
String basePackage = mappingBasePackage == null ? null : mappingBasePackage.getName();

return new String[]{basePackage};
}

/**
* Creates a {@link DynamoDBMappingContext} equipped with entity classes scanned from the mapping base package.
*
* @see #getMappingBasePackages()
* @return A newly created {@link DynamoDBMappingContext}
* @throws ClassNotFoundException if the class with {@link DynamoDBTable} annotation can't be loaded
*/
@Bean
public DynamoDBMappingContext dynamoDBMappingContext() throws ClassNotFoundException {

DynamoDBMappingContext mappingContext = new DynamoDBMappingContext();
mappingContext.setInitialEntitySet(getInitialEntitySet());

return mappingContext;
}

/**
* Scans the mapping base package for classes annotated with {@link DynamoDBTable}.
*
* @see #getMappingBasePackages()
* @return All classes with {@link DynamoDBTable} annotation
* @throws ClassNotFoundException if the class with {@link DynamoDBTable} annotation can't be loaded
*/
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {

Set<Class<?>> initialEntitySet = new HashSet<>();

String[] basePackages = getMappingBasePackages();

for (String basePackage:basePackages) {
LOGGER.trace("getInitialEntitySet. basePackage: {}", basePackage);

if (StringUtils.hasText(basePackage)) {
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(DynamoDBTable.class));

for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
LOGGER.trace("getInitialEntitySet. candidate: {}", candidate.getBeanClassName());
initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
AbstractDynamoDBConfiguration.class.getClassLoader()));
}
}
}

return initialEntitySet;
}
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDynamoDBConfiguration.class);

public abstract AmazonDynamoDB amazonDynamoDB();

public abstract AWSCredentials amazonAWSCredentials();

/**
* Return the base packages to scan for mapped {@link DynamoDBTable}s. Will
* return the package name of the configuration class' (the concrete class, not
* this one here) by default. So if you have a {@code com.acme.AppConfig}
* extending {@link AbstractDynamoDBConfiguration} the base package will be
* considered {@code com.acme} unless the method is overriden to implement
* alternate behaviour.
*
* @return the base package to scan for mapped {@link DynamoDBTable} classes or
* {@literal null} to not enable scanning for entities.
*/
protected String[] getMappingBasePackages() {

Package mappingBasePackage = getClass().getPackage();
String basePackage = mappingBasePackage == null ? null : mappingBasePackage.getName();

return new String[]{basePackage};
}

/**
* Creates a {@link DynamoDBMappingContext} equipped with entity classes scanned
* from the mapping base package.
*
* @see #getMappingBasePackages()
* @return A newly created {@link DynamoDBMappingContext}
* @throws ClassNotFoundException
* if the class with {@link DynamoDBTable} annotation can't be
* loaded
*/
@Bean
public DynamoDBMappingContext dynamoDBMappingContext() throws ClassNotFoundException {

DynamoDBMappingContext mappingContext = new DynamoDBMappingContext();
mappingContext.setInitialEntitySet(getInitialEntitySet());

return mappingContext;
}

/**
* Scans the mapping base package for classes annotated with
* {@link DynamoDBTable}.
*
* @see #getMappingBasePackages()
* @return All classes with {@link DynamoDBTable} annotation
* @throws ClassNotFoundException
* if the class with {@link DynamoDBTable} annotation can't be
* loaded
*/
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {

Set<Class<?>> initialEntitySet = new HashSet<>();

String[] basePackages = getMappingBasePackages();

for (String basePackage : basePackages) {
LOGGER.trace("getInitialEntitySet. basePackage: {}", basePackage);

if (StringUtils.hasText(basePackage)) {
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
false);
componentProvider.addIncludeFilter(new AnnotationTypeFilter(DynamoDBTable.class));

for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
LOGGER.trace("getInitialEntitySet. candidate: {}", candidate.getBeanClassName());
initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
AbstractDynamoDBConfiguration.class.getClassLoader()));
}
}
}

return initialEntitySet;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
*/
public abstract class BeanNames {

public static final String MAPPING_CONTEXT_BEAN_NAME = "dynamoDBMappingContext";
public static final String MAPPING_CONTEXT_BEAN_NAME = "dynamoDBMappingContext";

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,68 @@
import static org.springframework.data.config.ParsingUtils.getObjectFactoryBeanDefinition;

/**
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} to register a {@link AuditingEventListener} to transparently set auditing information on
* an entity.
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} to
* register a {@link AuditingEventListener} to transparently set auditing
* information on an entity.
*
* @author Vito Limandibhrata
*/
public class DynamoDBAuditingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return AuditingEventListener.class;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#
* getBeanClass(org.w3c.dom.Element)
*/
@Override
protected Class<?> getBeanClass(Element element) {
return AuditingEventListener.class;
}

/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#shouldGenerateId()
*/
@Override
protected boolean shouldGenerateId() {
return true;
}
/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#
* shouldGenerateId()
*/
@Override
protected boolean shouldGenerateId() {
return true;
}

/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
/*
* (non-Javadoc)
*
* @see
* org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#
* doParse(org.w3c.dom.Element,
* org.springframework.beans.factory.xml.ParserContext,
* org.springframework.beans.factory.support.BeanDefinitionBuilder)
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

String mappingContextRef = element.getAttribute("mapping-context-ref");
String mappingContextRef = element.getAttribute("mapping-context-ref");

if (!StringUtils.hasText(mappingContextRef)) {
if (!StringUtils.hasText(mappingContextRef)) {

BeanDefinitionRegistry registry = parserContext.getRegistry();
BeanDefinitionRegistry registry = parserContext.getRegistry();

if (!registry.containsBeanDefinition(MAPPING_CONTEXT_BEAN_NAME)) {
registry.registerBeanDefinition(MAPPING_CONTEXT_BEAN_NAME, new RootBeanDefinition(DynamoDBMappingContext.class));
}
if (!registry.containsBeanDefinition(MAPPING_CONTEXT_BEAN_NAME)) {
registry.registerBeanDefinition(MAPPING_CONTEXT_BEAN_NAME,
new RootBeanDefinition(DynamoDBMappingContext.class));
}

mappingContextRef = MAPPING_CONTEXT_BEAN_NAME;
}
mappingContextRef = MAPPING_CONTEXT_BEAN_NAME;
}

IsNewAwareAuditingHandlerBeanDefinitionParser parser = new IsNewAwareAuditingHandlerBeanDefinitionParser(
mappingContextRef);
parser.parse(element, parserContext);
IsNewAwareAuditingHandlerBeanDefinitionParser parser = new IsNewAwareAuditingHandlerBeanDefinitionParser(
mappingContextRef);
parser.parse(element, parserContext);

builder.addConstructorArgValue(getObjectFactoryBeanDefinition(parser.getResolvedBeanName(),
parserContext.extractSource(element)));
}
builder.addConstructorArgValue(
getObjectFactoryBeanDefinition(parser.getResolvedBeanName(), parserContext.extractSource(element)));
}
}
Loading