This annotation creates come objectd like DAO, Repository, ViewModel and User Interfase with full navigation of CRUD operations of this entity.
The ObjectGeneratorCE
annotation is used to automatically generate essential components of an entity, such as DAO, Repository, ViewModel, and the User Interface (UI). It provides full CRUD (Create, Read, Update, Delete) operations for the associated entity, including navigation support. This annotation simplifies the process of creating common components for an entity and ensures that all necessary infrastructure is automatically generated without needing to manually write boilerplate code.
type: GeneratorType
Defines the type of object generator. This could specify whether the entity should be generated as a full-fledged UI component or just a backend part like DAO or Repository.
Example: GeneratorType.Reference
or GeneratorType.Document
.
The specification of it:
enum class GeneratorType { *Reference*, *Document*, *Details*, *AccumulationRegister*, *InformationRegister*, *Report*, *ReportCursor*, *Free*, *Default*}
hasDetails: Boolean = false
Indicates whether the generated object will include detailed information about the entity, which can be useful for entities that have more complex attributes or require detailed UI rendering.
Default: false
(no detailed view)
detailsEntityClass: KClass<*> = Nothing::class
If set, this property defines the class to be used when generating the details screen for the entity. It allows you to link a separate entity that should be shown in more detail when interacting with the object.
Default: Nothing::class
(no details class linked)
label: String = "Undefined"
This label will be used to provide a user-friendly name for the entity when rendering the UI. It is typically used as the title or header of a form or table in the UI.
Default: "Undefined"
generationLevel: Int = [GenerationLevel](<https://wool-fontina-39f.notion.site/1bbac9e71431801b842cc74f5a6e8192>).UI
Defines the level of generation for the object. This can control whether the generated object is a UI-based entity or just a backend service.
Default: GenerationLevel.UI
(UI-based generation). You may have other levels
beforeSave: String = ""
This property specifies the name of a function to be called before saving an object to the database. It provides a hook to perform additional actions or validations before the actual save process.
Example: beforeSave = "validateBeforeSave"
Default: ""
(no hook)
Fun example:
fun beforeSave(sot:SaveOperationTypes,viewModel: RefAddressesEntityViewModel,ui:RefAddressesEntityUI){
if (sot==SaveOperationTypes.SAVE){
var date = viewModel.getField("date") as String
if (date=="null"||date.isBlank()) date="0"
var rdate = date.toLong()
viewModel.updateField("city","Saved "+ SimpleDataPickerDialog(0).convertMillisToDate(rdate))
}
else{
Toast.makeText (MyApplication1.appContext,"Another operation",Toast.LENGTH_SHORT).show()
}
}
beforeDelete: String = ""
Similar to beforeSave
, this property specifies the name of a function to be executed before deleting an object. It allows for custom actions before the deletion process.
Example: beforeDelete = "cleanupBeforeDelete"
Default: ""
(no hook)
Before Delete Example:
fun beforeDeleteUtility (delList: List<Any>?,viewModel: RefUtilitiesEntityViewModel,ui: RefUtilitiesEntityUI):Boolean{
for (item in delList ?: emptyList()) {
val curr = item as RefUtilitiesEntityExt //RefUtilitiesEntity + Ext
if(curr.link.describe.isNotBlank()){
Toast.makeText(MyApplication1.appContext,"Can't delete course of describe is not empty but [${curr.link.describe}]",Toast.LENGTH_SHORT).show()
return true
}
}
return false
@ObjectGeneratorCE(
type = GeneratorType.BOTH,
hasDetails = true,
label = "User Profile",
beforeSave = "validateUserProfile",
beforeDelete = "archiveUserProfile"
)
@Entity (.......)
data class UserProfile(
@PrimaryKey(autoGenerate = true)
override var id: Long,
override var date: Long,
override var name: String,
override var isMarkedForDeletion: Boolean,
................
): CommonReferenceEntity(id,date,name,isMarkedForDeletion), Parcelable {
// Entity properties and methods
}
ObjectGeneratorCE
annotation is applied to a class, it triggers the automatic generation of all the necessary components:
beforeSave
and beforeDelete
hooks allow you to inject custom logic before performing these operations. This is useful for adding validation, logging, or any pre-processing needed before saving or deleting the entity.[ObjectGeneratorCE](https://wool-fontina-39f.notion.site/ObjectGeneratorCE-1bbac9e71431806189c7f8b20d76aea4)