All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.babyfish.jimmer.sql.DraftInterceptor.kt Maven / Gradle / Ivy

The newest version!
package org.babyfish.jimmer.sql

import org.babyfish.jimmer.Draft
import org.babyfish.jimmer.meta.TypedProp

/**
 * Before saving draft, give user a chance to modify it
 *
 * 

This interface is very similar to another interface * [DraftPreProcessor], * the differences between the two are as follows: *

    *
  • [DraftPreProcessor] is more conducive to SQL optimization, but has weaker functions
  • *
  • This interface has stronger features but is not carp SQL optimized
  • *
*

* *

It also queries the original entity with * `id`, `key` and other properties returned by [.dependencies] to help user to decide how to modify draft

* * The default behavior of `save` with `UPDATE_ONLY` or `update` is not querying original entity. * However, if [.dependencies] returns some properties which is neither `id` nor `key`, * the default behavior will be broken, original entity will be queried even if the save mode is `UPDATE_ONLY` * * @param The entity type * @param The draft type * * @see DraftPreProcessor */ interface DraftInterceptor { /** * Adjust draft before save * @param draft The draft can be modified, `id` and `key` properties cannot be changed, otherwise, exception will be raised. * @param original The original object * * * null for insert * * non-null for update, with `id`, `key` and other properties * returned by [.dependencies] */ fun beforeSave(draft: D, original: E?) /** * Specify which properties of original entity must be loaded * *

Note

*
    *
  • The return value must be stable, It will only be called once, so an unstable return is meaningless
  • *
  • All elements must be properties which is mapped by database field directly
  • *
* * @return The properties must be loaded, can return null. */ fun dependencies(): Collection>? { return emptyList() } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy