Skip to main content

Static polymorphism

The AgilEntity framework has a db vendor agnostic sub api that allows the client code for the platform to interact with the clusters loaded database without knowing the specific vendor type of the system in place. This enables the client programmers to write standard ANSI compliant SQL to perform calls on the the various tables added to the datastore. The design of the datastore promotes a relational model between Entities that are managed in an Entity relations table. Other Entities have specific mapping relationships as well but all db access occurs through the API. This is done using an abstraction of the db accessing methods through a class called CreateTable. The CreateTable base class , which is abstract as defined using the java OO syntax is extended by sub classes that implement the specific functionality that is required to mediate specific vendor databases. The base class enforces implemenations for methods that perform several of the following functions that tend to be database variable.
  • date/time conversion and formatting
  • editColumn
  • addRow
  • createTable
  • select for Vendor

These functions will vary depending on the vendor in use. For example, the date time format defaults vary significantly between mysql , mssql server and oracle. By building the change into a method in the db vendor class and calling those polymorphically we get automatic db agnostic operation. Some of the methods are purely abstract , others are abstract and static these methods allow invoking subclass specific implemenations without instantiating instances of the subclass objects. This is done using the static polymorphism pattern that I describe below:

The java API allows deep control over how methods and classes are called, it also allows us to define how the jvm loads up class path locations for reference of class files. This class loading mechanism is the power behind dynamic run time extension capabilities of many java application servers. These abilities are part of what java calls the reflection API. Static polymorphism uses the Class class to instantiate an object from its FQCN (fully qualified class name). This allows static polymorphism to proceed by having the a concrete static base class method call an implementation of a FQCN named subclass of that base class hieararchy...thus effecting a polymorphic call on a static method.

1) Define the base class of your inheritance hieararchy. In my case it was the "CreateTable" class which was defined as a public and abstract class (to allow both concrete and abstract implemenation signatures which is important to enable the static polymorphism.)

public abstract class CreateTable {

//empty arg abstract method goes here ...see below.


2) define the empty arg. abstract method signature for the method we require to override via polymorphism
in inheriting classes. This should be public or protected so that the subclasses can see it and thus be constrained to provide implemenations. The reason the argument is empty is that we just want to extract the db specific version of the function being requested. In this case the db specific default time pattern. We have the method name but we now need a way to statically select the class which is invoking that method. That is where the abstract FQCN argument method comes in as shown in 3.

public abstract class CreateTable {

public abstract String timePattern() ;

//static FQCN argument method with string argument goes below...


3) The implemented string argument version of timePattern() is shown. The green call to a method "getVendorInstance(fqcn)" is where the reflection happens as shown in the method implemenation.

public abstract class CreateTable {

public abstract String timePattern() ;

public static String timePattern(String fqcn) {
try {
//Extract in instance of the currently loaded derived createTable class.
CreateTable vinny = this.getVendorInstance(fqcn);
return vinny.timePattern();
} catch (GVIOException efio) {
throw new EntegraDBAccessException("IO Error from CreateTable static insertForVendorDB method.",efio);


public static CreateTable getVendorInstance(String vndrfqcn) {
//From the grouptype fqcn string generate a Class object.
Class childclass = Class.forName(vndrfqcn);

//From the class object generate a new instance of the class specified by the fqcn in object form.
java.lang.Object childobject = childclass.newInstance();
//caste object to its known basetype and return
return (CreateTable)childobject;


In my framework, the call to "Class.forName(..)" is abstracted further to a custom class loader, this class loader overrides the ClassLoader class of the java API to allow custom loading of packages from specific paths so that the framework can dynamically load classes during run time. This is how the framework enables run time extensibility just like standard java web application servers do.

4) The final step is to create a subclass of CreateTable and implement the forced implemenation of the abstract method signature for the no argument version of "timePattern()" It is this version of the method that is called when the corresponding "fqcn" is provided in the string argument method of the same name. Because the object is instanced from the class name at run time (when the name is specified) a dynamic selection of the code (polymorphism) is realized despite the call being made on a static method. In my framework the "fqcn" string comes from the system bootstrap configuration class DPSConfig which bootstraps from settings indicated in an xml configuration file. The file is managable by the UI , so changing back end db's is trivially performed without requiring down time on any of the nodes in the cluster. As well the desire to call necessary db vendor agnostic methods is achieved from all client code that utilizes the static method and passes in the "fqcn" from the system bootstrap settings without knowledge or care of which db vendor class it happens to be. Below I provide an example for a hypothetical subclass with customization for the DB2 DBMS.

public class CreateTableDB2 extends CreateTable {

public String timePattern() {
return " hh:mi:ss ";


Using static polymorphism has allowed me to get around the sticky problem of calling vendor specific methods in a static way without instancing the subclass that currently maps to the db in use on the system and is straight forward to implement, you might find it useful in your designs.


Popular posts from this blog

Engineers versus Programmers

I have found as more non formally trained people enter the coding space, the quality of code that results varies in an interesting way.

The formalities of learning to code in a structured course at University involve often strong focus on "correctness" and efficiency in the form of big O representations for the algorithms created.

Much less focus tends to be placed on what I'll call practical programming, which is the type of code that engineers (note I didn't use "programmers" on purpose) must learn to write.

Programmers are what Universities create, students that can take a defined development environment and within in write an algorithm for computing some sequence or traversing a tree or encoding and decoding a string. Efficiency and invariant rules are guiding development missions. Execution time for creating the solution is often a week or more depending on the professor and their style of teaching code and giving out problems. This type of coding is devo…

Highly targeted Cpg vaccine immunotherapy for a range of cancer


This will surely go down as a seminal advance in cancer therapy. It reads like magic:

So this new approach looks for the specific proteins that are associated with a given tumors resistance to attack by the body's T cells, it then adjusts those T cells to be hyper sensitive to the specific oncogenic proteins targeted. These cells become essentially The Terminator​ T cells in the specific tumor AND have the multiplied effect of traveling along the immune pathway of spreading that the cancer many have metastasized. This is huge squared because it means you can essentially use targeting one tumor to identify and eliminate distal tumors that you many not even realize exist.

This allows the therapy for treating cancer to, for the first time; end the "wack a mole" problem that has frustrated traditional shot gun methods of treatment involving radiation and chemotherapy ...which by their nature unfortunately damage parts of the body that are not cancer laden but …

AgilEntity Architecture: Action Oriented Workflow

Permissions, fine grained versus management headache
The usual method for determining which users can perform a given function on a given object in a managed system, employs providing those Users with specific access rights via the use of permissions. Often these permissions are also able to be granted to collections called Groups, to which Users are added. The combination of Permissions and Groups provides the ability to provide as atomic a dissemination of rights across the User space as possible. However, this granularity comes at the price of reduced efficiency for managing the created permissions and more importantly the Groups that collect Users designated to perform sets of actions. Essentially the Groups serve as access control lists in many systems, which for the variable and often changing environment of business applications means a need to constantly update the ACL’s (groups) in order to add or remove individuals based on their ability to perform certain actions. Also, the…