Skip to content

Commit

Permalink
# implemented possibility to generate open entities
Browse files Browse the repository at this point in the history
  • Loading branch information
sbra0902 committed Nov 25, 2020
1 parent 2a1b812 commit b4ac55d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ enum Type {

Class<?> value() default Void.class;

boolean modifierOpen() default false;

Type type() default Type.READ_AND_WRITE;

String database() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class EntityGeneration {
.addFunction(toMap(holder, useSuspend))
.addFunction(BuilderClassGeneration.generateBuilderFun())

if(holder.modifierOpen){
typeBuilder.addModifiers(KModifier.OPEN)
}

for (fieldHolder in holder.allFields) {

fieldHolder.builderSetter(holder.dbName, holder.`package`, holder.entitySimpleName, true)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object EntityFactory {

fun createEntityHolder(cblEntityElement: Element, allWrappers: List<String>, allBaseModels: Map<String, BaseModelHolder>): EntityHolder {
val annotation = cblEntityElement.getAnnotation(Entity::class.java)
return create(cblEntityElement, EntityHolder(annotation.database, annotation.type), allWrappers, allBaseModels) as EntityHolder
return create(cblEntityElement, EntityHolder(annotation.database, annotation.modifierOpen, annotation.type), allWrappers, allBaseModels) as EntityHolder
}

fun createBaseModelHolder(cblEntityElement: Element, allWrappers: List<String>): BaseModelHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.kaufland.model.entity

import kaufland.com.coachbasebinderapi.Entity

class EntityHolder(val dbName: String, val entityType : Entity.Type) : BaseEntityHolder()
class EntityHolder(val dbName: String, val modifierOpen: Boolean, val entityType : Entity.Type) : BaseEntityHolder()
5 changes: 1 addition & 4 deletions demo/src/main/java/kaufland/com/demo/entity/TestClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package kaufland.com.demo.entity

import com.couchbase.lite.Blob
import kaufland.com.coachbasebinderapi.*
import kaufland.com.coachbasebinderapi.query.Queries
import kaufland.com.coachbasebinderapi.query.Query
import kaufland.com.demo.MainActivity

@Entity(database = "mydb_db")
@Entity(database = "mydb_db", modifierOpen = true)
@MapWrapper
@Fields(
Field(name = "type", type = String::class, defaultValue = "something", readonly = true),
Expand Down

0 comments on commit b4ac55d

Please sign in to comment.