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

org.iternine.jeppetto.dao.enhance.updateObject.vm Maven / Gradle / Ivy

The newest version!
#* @vtlvariable name="getters" type="javassist.CtMethod[]" *#
#* @vtlvariable name="adders" type="java.lang.reflect.Method[]" *#
#* @vtlvariable name="base" type="javassist.CtClass" *#
#* @vtlvariable name="_" type="org.iternine.jeppetto.enhance.TemplateHelper" *#
#* @vtlvariable name="updateObjectHelper" type="org.iternine.jeppetto.dao.updateobject.UpdateObjectHelper" *#
#set( $baseName = $base.getName() )
#set( $Q = '"')
public $_.cls("${baseName}$UpdateObject").ext($base).impl("org.iternine.jeppetto.dao.updateobject.UpdateObject") {

    #set( $thisName = $_.clsName() )

    //-------------------------------------------------------------
    // Variables - Private
    //-------------------------------------------------------------

    $_.field("private final java.util.Map __updates = new java.util.HashMap();")


    //-------------------------------------------------------------
    // Methods - Overrides
    //-------------------------------------------------------------

    #foreach ( $getter in $getters )
    #set( $getterName = $getter.getName() )
    #set( $field = $_.fieldFor($getterName) )
    #set( $setterName = $_.asSetter($field) )
    #set( $returnType = $_.returnTypeOf($getter) )
    #set( $returnTypeName = $returnType.getName() )

    ## Special case blobs
    #if ( $returnTypeName == '[B')
        #set ( $returnTypeName = 'byte[]' )
    #end

    #if ( $updateObjectHelper.needsUpdateObjectConversion($returnType) )
    $_.method("
    public $returnTypeName $getterName() {
        $returnTypeName value = ($returnTypeName) __updates.get(${Q}$field${Q});

        if (value == null) {
            #if ( $updateObjectHelper.isAssignableFromList($returnType) )
            value = new org.iternine.jeppetto.dao.updateobject.UpdateList(${Q}$updateObjectHelper.getListIndexFormat()${Q});
            #elseif ( $updateObjectHelper.isAssignableFromMap($returnType) )
            value = new org.iternine.jeppetto.dao.updateobject.UpdateMap();
            #elseif ( $updateObjectHelper.isAssignableFromSet($returnType) )
            ## value = new org.iternine.jeppetto.dao.updateobject.UpdateSet();
            value = new java.util.HashSet();
            #else
            value = ($returnTypeName) $updateObjectHelper.getEnhancerMethod()($returnTypeName .class).newInstance();
            #end

            __updates.put(${Q}$field${Q}, value);
        }

        return value;
    }")
    #end

    $_.method("
    public void $setterName($returnTypeName value) {
        // TODO: handle id
        #if ( $returnType.isPrimitive() )
        __updates.put(${Q}$field${Q}, org.iternine.jeppetto.enhance.ReferenceUtil.asObject(value));
        #else
        __updates.put(${Q}$field${Q}, value);
        #end
    }")
    #end


    #foreach ( $adder in $adders )
    #set( $adderName = $adder.getName() )
    #set( $addedType = $adder.getParameterTypes()[0] )
    #set( $field = $updateObjectHelper.getAdderField($adderName) )
    $_.method("
    public void $adderName($addedType.getName() value) {
        #if ( $addedType.isPrimitive() )
        Number valueObject = (Number) org.iternine.jeppetto.enhance.ReferenceUtil.asObject(value);
        __updates.put(${Q}$field${Q}, new org.iternine.jeppetto.dao.updateobject.NumericIncrement(valueObject));
        #else
        __updates.put(${Q}$field${Q}, new org.iternine.jeppetto.dao.updateobject.NumericIncrement(value));
        #end
    }")
    #end


    //-------------------------------------------------------------
    // Implementation - UpdateObject
    //-------------------------------------------------------------

    $_.method("
    public java.util.Map __getUpdates() {
        return __updates;
    }
    ")
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy