lundi 27 avril 2020

How to cache class' instances in Groovy

I have the following method:

def <T> T getImpl(Class<T> category)
{
        def queryGetter

        if (DDLTool.isOracle())
        {
            queryGetter = // getting oracle implementation based on category (Portal|Portal365)
        }
        else if (DDLTool.isMSSQL())
        {
            queryGetter = // getting mssql implementation based on category (Portal|Portal365)
        }
        else if (DDLTool.isPostgres())
        {
            queryGetter = // getting postgres implementation based on category (Portal|Portal365)
        }

        return queryGetter
}

category can be the following:

  1. Portal.class
  2. Portal365.class

Hierarchy scheme:

Category -> Portal | Portal365 -> PostgresQueryGetterPortal/MssqlQueryGetterPortal/OracleQueryGetterPortal |  PostgresQueryGetterPortal356/MssqlQueryGetterPortal365/OracleQueryGetterPortal365

So, I need to get needed implementation based on category (Portal|Portal365). Also, I shouldn't use classpath everytime I call the method. A have to cache them somehow

How can I do that?

Thanks in advance





Aucun commentaire:

Enregistrer un commentaire