15
15
*/
16
16
package org .socialsignin .spring .data .dynamodb .repository .config ;
17
17
18
+ import java .util .HashMap ;
19
+ import java .util .Map ;
20
+
21
+ import org .slf4j .Logger ;
22
+ import org .slf4j .LoggerFactory ;
18
23
import org .socialsignin .spring .data .dynamodb .mapping .DynamoDBMappingContext ;
19
24
import org .socialsignin .spring .data .dynamodb .repository .support .DynamoDBRepositoryFactoryBean ;
25
+ import org .springframework .beans .factory .config .BeanDefinition ;
20
26
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
27
+ import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
21
28
import org .springframework .core .annotation .AnnotationAttributes ;
29
+ import org .springframework .data .config .BeanComponentDefinitionBuilder ;
22
30
import org .springframework .data .config .ParsingUtils ;
23
31
import org .springframework .data .repository .config .AnnotationRepositoryConfigurationSource ;
24
32
import org .springframework .data .repository .config .RepositoryConfigurationExtensionSupport ;
33
+ import org .springframework .data .repository .config .RepositoryConfigurationSource ;
25
34
import org .springframework .data .repository .config .XmlRepositoryConfigurationSource ;
26
35
import org .springframework .util .Assert ;
27
36
import org .springframework .util .StringUtils ;
33
42
*/
34
43
public class DynamoDBRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport {
35
44
45
+ private static final Logger LOGGER = LoggerFactory .getLogger (DynamoDBRepositoryConfigExtension .class );
46
+
36
47
private static final String DEFAULT_AMAZON_DYNAMO_DB_BEAN_NAME = "amazonDynamoDB" ;
37
48
38
49
private static final String DYNAMO_DB_MAPPER_CONFIG_REF = "dynamodb-mapper-config-ref" ;
@@ -42,6 +53,8 @@ public class DynamoDBRepositoryConfigExtension extends RepositoryConfigurationEx
42
53
private static final String AMAZON_DYNAMODB_REF = "amazon-dynamodb-ref" ;
43
54
44
55
private static final String MAPPING_CONTEXT_REF = "mapping-context-ref" ;
56
+
57
+ private BeanDefinitionRegistry registry ;
45
58
46
59
@ Override
47
60
public String getRepositoryFactoryBeanClassName () {
@@ -54,7 +67,6 @@ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfi
54
67
55
68
postProcess (builder , attributes .getString ("amazonDynamoDBRef" ), attributes .getString ("dynamoDBMapperConfigRef" ),
56
69
attributes .getString ("dynamoDBOperationsRef" ), attributes .getString ("mappingContextRef" ));
57
-
58
70
}
59
71
60
72
/*
@@ -68,9 +80,9 @@ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfi
68
80
*/
69
81
@ Override
70
82
public void postProcess (BeanDefinitionBuilder builder , XmlRepositoryConfigurationSource config ) {
71
-
72
83
Element element = config .getElement ();
73
84
85
+
74
86
ParsingUtils .setPropertyReference (builder , element , AMAZON_DYNAMODB_REF , "amazonDynamoDB" );
75
87
ParsingUtils .setPropertyReference (builder , element , DYNAMO_DB_MAPPER_CONFIG_REF , "dynamoDBMapperConfig" );
76
88
ParsingUtils .setPropertyReference (builder , element , DYNAMO_DB_OPERATIONS_REF , "dynamoDBOperations" );
@@ -100,11 +112,25 @@ private void postProcess(BeanDefinitionBuilder builder, String amazonDynamoDBRef
100
112
}
101
113
}
102
114
103
- if (StringUtils .hasText (dynamoDBMappingContextRef )) {
104
- builder .addPropertyReference ("dynamoDBMappingContext" , dynamoDBMappingContextRef );
105
- } else {
106
- builder .addPropertyValue ("dynamoDBMappingContext" , new DynamoDBMappingContext ());
115
+ if (!StringUtils .hasText (dynamoDBMappingContextRef )) {
116
+ BeanDefinitionBuilder dynamoDBMappingContextBuilder = BeanDefinitionBuilder .genericBeanDefinition (DynamoDBMappingContext .class );
117
+ dynamoDBMappingContextRef = getModulePrefix () + "-dynamoDBMappingContext" ;
118
+
119
+ LOGGER .debug ("Adding bean <{}> of type <{}>" , dynamoDBMappingContextRef , dynamoDBMappingContextBuilder .getBeanDefinition ());
120
+
121
+ assert registry != null ;
122
+ registry .registerBeanDefinition (dynamoDBMappingContextRef , dynamoDBMappingContextBuilder .getBeanDefinition ());
107
123
}
124
+ builder .addPropertyReference ("dynamoDBMappingContext" , dynamoDBMappingContextRef );
125
+ }
126
+
127
+ @ Override
128
+ public void registerBeansForRoot (BeanDefinitionRegistry registry ,
129
+ RepositoryConfigurationSource configurationSource ) {
130
+ super .registerBeansForRoot (registry , configurationSource );
131
+
132
+ // Store for later to be used by #postProcess
133
+ this .registry = registry ;
108
134
}
109
135
110
136
@ Override
0 commit comments