Skip to content

Commit

Permalink
fix: issues derjust#230 and derjust#233 (resolve DynamoDBRepositoryCo…
Browse files Browse the repository at this point in the history
…nfigExtension conflicts)
  • Loading branch information
tiagocpeixoto committed Jun 15, 2019
1 parent 1fa0759 commit 6e75368
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfiguratio

private Map<String, String> dynamoDBTemplateCache = new HashMap<>();
private void postProcess(BeanDefinitionBuilder builder, String repositoryName, String amazonDynamoDBRef,
String dynamoDBMapperConfigRef, String dynamoDBOperationsRef, String dynamoDBMappingContextRef) {
String dynamoDBMapperConfigRef, String dynamoDBOperationsRef, String dynamoDBMappingContextRef) {

if (StringUtils.hasText(dynamoDBOperationsRef)) {
builder.addPropertyReference("dynamoDBOperations", dynamoDBOperationsRef);
Expand All @@ -130,20 +130,23 @@ private void postProcess(BeanDefinitionBuilder builder, String repositoryName, S
.computeIfAbsent(getBeanNameWithModulePrefix("DynamoDBTemplate-" + dynamoDBRef), ref -> {
BeanDefinitionBuilder dynamoDBTemplateBuilder = BeanDefinitionBuilder
.genericBeanDefinition(DynamoDBTemplate.class);
// AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper,
// DynamoDBMapperConfig dynamoDBMapperConfig
dynamoDBTemplateBuilder.addConstructorArgReference(dynamoDBRef);
dynamoDBTemplateBuilder.addConstructorArgReference(this.dynamoDBMapperName);

if (StringUtils.hasText(dynamoDBMapperConfigRef)) {
dynamoDBTemplateBuilder.addConstructorArgReference(dynamoDBMapperConfigRef);
} else {
dynamoDBTemplateBuilder.addConstructorArgReference(this.dynamoDBMapperConfigName);
}

registry.registerBeanDefinition(ref, dynamoDBTemplateBuilder.getBeanDefinition());
return ref;
});
}

builder.addPropertyReference("dynamoDBOperations", dynamoDBOperationsRef);

/* Fix issue #233 - these statements were commented on as they are not supposed to be necessary */
// if (StringUtils.hasText(dynamoDBMapperConfigRef)) {
// builder.addPropertyReference("dynamoDBMapperConfig",
// dynamoDBMapperConfigRef);
// }
}

if (!StringUtils.hasText(dynamoDBMappingContextRef)) {
Expand All @@ -159,7 +162,7 @@ private void postProcess(BeanDefinitionBuilder builder, String repositoryName, S
}

protected void registerAndSetPostProcessingBeans(BeanDefinitionBuilder builder, BeanDefinitionRegistry registry,
String dynamoDBMappingContextRef) {
String dynamoDBMappingContextRef) {
String tableSynchronizerName = registerEntity2DynamoDBTableSynchronizer(registry, dynamoDBMappingContextRef);
builder.addPropertyReference("entity2DynamoDBTableSynchronizer", tableSynchronizerName);

Expand All @@ -170,7 +173,7 @@ protected void registerAndSetPostProcessingBeans(BeanDefinitionBuilder builder,

private final Map<String, String> entity2DynamoDBTableSynchronizerCache = new ConcurrentHashMap<>();
private String registerEntity2DynamoDBTableSynchronizer(BeanDefinitionRegistry registry,
String dynamoDBMappingContextRef) {
String dynamoDBMappingContextRef) {
assert registry != null;

return entity2DynamoDBTableSynchronizerCache.computeIfAbsent(dynamoDBMappingContextRef, ref -> {
Expand All @@ -186,8 +189,12 @@ private String registerEntity2DynamoDBTableSynchronizer(BeanDefinitionRegistry r
}

private final Map<String, String> dynamoDBMappingContextProcessorCache = new ConcurrentHashMap<>();

private String dynamoDBMapperName;

private String dynamoDBMapperConfigName;
private String registerDynamoDBMappingContextProcessor(BeanDefinitionRegistry registry,
String dynamoDBMappingContextRef) {
String dynamoDBMappingContextRef) {
assert registry != null;

return dynamoDBMappingContextProcessorCache.computeIfAbsent(dynamoDBMappingContextRef, ref -> {
Expand Down Expand Up @@ -222,7 +229,7 @@ private String registerDynamoDBMappingContext(BeanDefinitionRegistry registry) {

@Override
public void registerBeansForRoot(BeanDefinitionRegistry registry,
RepositoryConfigurationSource configurationSource) {
RepositoryConfigurationSource configurationSource) {
super.registerBeansForRoot(registry, configurationSource);

// Store for later to be used by #postProcess, too
Expand All @@ -231,16 +238,16 @@ public void registerBeansForRoot(BeanDefinitionRegistry registry,
// Fix issue #233
Optional dynamoDBMapperConfigRef = configurationSource.getAttribute("dynamoDBMapperConfigRef");
if (!dynamoDBMapperConfigRef.isPresent()) {
BeanDefinitionBuilder dynamoDBMapperConfigBuiilder = BeanDefinitionBuilder
BeanDefinitionBuilder dynamoDBMapperConfigBuilder = BeanDefinitionBuilder
.genericBeanDefinition(DynamoDBMapperConfigFactory.class);
registry.registerBeanDefinition(getBeanNameWithModulePrefix("DynamoDBMapperConfig"),
dynamoDBMapperConfigBuiilder.getBeanDefinition());
dynamoDBMapperConfigBuilder.getBeanDefinition());
}

this.dynamoDBMapperName = getBeanNameWithModulePrefix("DynamoDBMapper");
BeanDefinitionBuilder dynamoDBMapperBuilder = BeanDefinitionBuilder
.genericBeanDefinition(DynamoDBMapperFactory.class);
registry.registerBeanDefinition(getBeanNameWithModulePrefix("DynamoDBMapper"),
dynamoDBMapperBuilder.getBeanDefinition());
registry.registerBeanDefinition(this.dynamoDBMapperName, dynamoDBMapperBuilder.getBeanDefinition());
}

protected String getBeanNameWithModulePrefix(String baseBeanName) {
Expand Down

0 comments on commit 6e75368

Please sign in to comment.