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

io.vanillabp.springboot.adapter.SpringDataUtil Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package io.vanillabp.springboot.adapter;

import org.springframework.data.annotation.Id;
import org.springframework.data.repository.CrudRepository;

/**
 * Utility to handle Spring data repositories. A string identifier is expected for workflow entities.
 */
public interface SpringDataUtil {

    /**
     * Determine the repository for the given object.
     * 
     * @param  The entity's expected type.
     * @param entity The entity
     * @return The repository
     */
     CrudRepository getRepository(O entity);
    
    /**
     * Determine the repository for the given type.
     * 
     * @param  The entity's expected type.
     * @param type The given entity's type.
     * @return The repository
     */
     CrudRepository getRepository(Class type);

    /**
     * Determine the entity's object identifier.
     * 
     * @param entity The entity
     * @return The id
     * @see Id
     */
     I getId(Object entity);

    /**
     * Determine the entity's object identifier's parameter name.
     *
     * @param type The given entity's type.
     * @return The entity's object identifier's parameter name.
     */
    String getIdName(Class type);
    
    /**
     * Determine the entity's object identifier's type.
     * 
     * @param type The given entity's type.
     * @return The entity's object identifier's type.
     */
    Class getIdType(Class type);
    
    /**
     * Unproxy the entity. This forces to load data if the proxy is not yet initialized. 
     * 
     * @param  The entity's type
     * @param entity The entity
     * @return The initialized entity
     */
     O unproxy(O entity);
    
    /**
     * Determines whether the given entity was loaded/persisted from/to DB before
     * or it is a POJO (e.g. right before persisting).
     * 
     * @param  the entity's type
     * @param entityClass The entity's class
     * @param entity The entity
     * @return Entity was loaded/persisted from/to DB before
     */
     boolean isPersistedEntity(Class entityClass, O entity);
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy