-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Kaufland/feature/typeConversion
# implemented type conversion
- Loading branch information
Showing
15 changed files
with
169 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
couchbase-entity-api/src/main/java/kaufland/com/coachbasebinderapi/TypeConversion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kaufland.com.coachbasebinderapi; | ||
|
||
public interface TypeConversion { | ||
|
||
Object write(Object value); | ||
|
||
Object read(Object value); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
couchbase-entity/src/main/java/com/kaufland/generation/TypeConversionMethodsGeneration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.kaufland.generation; | ||
|
||
import com.squareup.javapoet.CodeBlock; | ||
import com.squareup.javapoet.MethodSpec; | ||
import com.squareup.javapoet.TypeName; | ||
import com.squareup.javapoet.TypeVariableName; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import kaufland.com.coachbasebinderapi.PersistenceConfig; | ||
import kaufland.com.coachbasebinderapi.TypeConversion; | ||
|
||
public class TypeConversionMethodsGeneration { | ||
|
||
public static final String READ_METHOD_NAME = "read"; | ||
|
||
public static final String WRITE_METHOD_NAME = "write"; | ||
|
||
private static final String GET_TYPE_CONVERSION_METHOD = "getInstance().getConnector().getTypeConversions"; | ||
|
||
public Collection<MethodSpec> generate() { | ||
|
||
return Arrays.asList( | ||
MethodSpec.methodBuilder(READ_METHOD_NAME). | ||
addParameter(TypeName.OBJECT, "value"). | ||
addParameter(Class.class, "clazz"). | ||
addTypeVariable(TypeVariableName.get("T")). | ||
returns(TypeVariableName.get("T")). | ||
addCode(CodeBlock.builder(). | ||
addStatement("$N conversion = $N." + GET_TYPE_CONVERSION_METHOD + "().get(clazz)", TypeConversion.class.getCanonicalName(), PersistenceConfig.class.getCanonicalName()). | ||
beginControlFlow("if(conversion == null)"). | ||
addStatement("return (T) value"). | ||
endControlFlow(). | ||
addStatement("return (T) conversion.read(value)"). | ||
build()).build(), | ||
|
||
MethodSpec.methodBuilder(WRITE_METHOD_NAME). | ||
addParameter(TypeName.OBJECT, "value"). | ||
addParameter(Class.class, "clazz"). | ||
addTypeVariable(TypeVariableName.get("T")). | ||
returns(TypeVariableName.get("T")). | ||
addCode(CodeBlock.builder(). | ||
addStatement("$N conversion = $N." + GET_TYPE_CONVERSION_METHOD + "().get(clazz)", TypeConversion.class.getCanonicalName(), PersistenceConfig.class.getCanonicalName()). | ||
beginControlFlow("if(conversion == null)"). | ||
addStatement("return (T) value"). | ||
endControlFlow(). | ||
addStatement("return (T) conversion.write(value)"). | ||
build()).build() | ||
|
||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
demo/src/main/java/kaufland/com/demo/entity/ProductDetails.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters