Have a look how the JPA-variables are hooked in. If you want to make custom variable, you should extend the VariableType and implement your own, storing the data you need in the available db-fields on the variable or in byte-array, exposed to you in the VariableType.
If you also need some kind of initialisation of a transaction/entitymanager of some kind, have a look at EntityManagerSession and EntityManagerSessionFactory. These participate in the command-context and allow the JPAVariables to get hold of the entitymanager in the current command-context to fetch the actual entity when the variable is loaded…
The type and factory can be plugged in, no need to alter any activiti-sourcecode.