diff --git a/couchbase-entity-api/src/main/java/kaufland/com/coachbasebinderapi/IEntity.kt b/couchbase-entity-api/src/main/java/kaufland/com/coachbasebinderapi/IEntity.kt new file mode 100644 index 00000000..e7e61ad4 --- /dev/null +++ b/couchbase-entity-api/src/main/java/kaufland/com/coachbasebinderapi/IEntity.kt @@ -0,0 +1,5 @@ +package kaufland.com.coachbasebinderapi + +interface IEntity : MapSupport { + fun getId(): String? +} \ No newline at end of file diff --git a/couchbase-entity/src/main/java/com/kaufland/generation/model/EntityGeneration.kt b/couchbase-entity/src/main/java/com/kaufland/generation/model/EntityGeneration.kt index 219c9185..cefc2591 100644 --- a/couchbase-entity/src/main/java/com/kaufland/generation/model/EntityGeneration.kt +++ b/couchbase-entity/src/main/java/com/kaufland/generation/model/EntityGeneration.kt @@ -13,7 +13,11 @@ import java.util.* class EntityGeneration { private val id: FunSpec - get() = FunSpec.builder("getId").addModifiers(KModifier.PUBLIC).returns(TypeUtil.string().copy(nullable = true)).addStatement("return mDoc.get(%N) as %T", "_ID", TypeUtil.string().copy(nullable = true)).build() + get() = FunSpec.builder("getId") + .addModifiers(KModifier.PUBLIC, KModifier.OVERRIDE) + .returns(TypeUtil.string().copy(nullable = true)) + .addStatement("return mDoc.get(%N) as %T", "_ID", TypeUtil.string().copy(nullable = true)) + .build() fun generateModel(holder: EntityHolder, useSuspend : Boolean): FileSpec { @@ -42,7 +46,7 @@ class EntityGeneration { val typeBuilder = TypeSpec.classBuilder(holder.entitySimpleName) .addModifiers(KModifier.PUBLIC) - .addSuperinterface(TypeUtil.mapSupport()) + .addSuperinterface(TypeUtil.iEntity()) .addSuperinterface(holder.interfaceTypeName) .addFunction(EnsureTypesGeneration.ensureTypes(holder, false)) .addFunction(CblDefaultGeneration.addDefaults(holder, false)) diff --git a/couchbase-entity/src/main/java/com/kaufland/util/TypeUtil.kt b/couchbase-entity/src/main/java/com/kaufland/util/TypeUtil.kt index 5f8b6118..37d7e0c5 100644 --- a/couchbase-entity/src/main/java/com/kaufland/util/TypeUtil.kt +++ b/couchbase-entity/src/main/java/com/kaufland/util/TypeUtil.kt @@ -5,6 +5,8 @@ import com.squareup.kotlinpoet.* import javax.lang.model.type.TypeMirror import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import kaufland.com.coachbasebinderapi.IEntity +import kaufland.com.coachbasebinderapi.MapSupport import kaufland.com.coachbasebinderapi.mapify.IMapper import kaufland.com.coachbasebinderapi.mapify.IMapifyable import kaufland.com.coachbasebinderapi.mapify.Mapifyable @@ -89,7 +91,7 @@ object TypeUtil { } fun mapSupport(): TypeName { - return ClassName("kaufland.com.coachbasebinderapi", "MapSupport") + return MapSupport::class.asTypeName() } fun iMapper(typename: TypeName): TypeName { @@ -108,6 +110,10 @@ object TypeUtil { return SerializableMapifyable::class.asTypeName().parameterizedBy(typename) } + fun iEntity(): TypeName { + return IEntity::class.asTypeName() + } + fun clazz(typename: TypeName) : TypeName{ return ClassName("java.lang", "Class").parameterizedBy(typename) }