Feature request: automatic registration like in twig 2.0

40 views
Skip to first unread message

Alex Rhomberg

unread,
Mar 18, 2013, 3:05:29 PM3/18/13
to twig-p...@googlegroups.com
I would like to have automatic registration and creation of type names like in Twig 1.0.4, using full class names. I don't mind the long entity names.

This could be done with a switch, e.g. DefaultConfiguration.setAutoRegister(true);

If I want to do this myself, can I do the following?
  • subclass AnnotationConfiguration and override typeToName(Class<?> type) with an automatic registration
  • subclass ObjectDatastoreFactory and override getConfiguration() to instantiate my own Configuration class
Regards
Alex

John Patterson

unread,
Mar 18, 2013, 5:13:24 PM3/18/13
to twig-p...@googlegroups.com
Good point.

--
You received this message because you are subscribed to the Google Groups "twig-persist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to twig-persist...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alex Rhomberg

unread,
Mar 23, 2013, 11:46:34 AM3/23/13
to twig-p...@googlegroups.com
I am now using Twig 2.0 in a way that is more compatible to Twig 1.0.4:
I subclassed AnnotationConfiguration to create a Configuration that supports auto-registering and using the long class names as kind names.

Then I created my own factory where I can set the Configuration to use for new datastores.
Additionally, the datastores are created as Singleton per thread with the help of ThreadLocal.
This avoids the multi-thread issues with the 2.0 ObjectDatastore but it also avoids another incompatibility where I load a parent early in the thread and store children later, without explicitly keeping the same datastore.

I attached both the configuration and the factory; feel free to incorporate anything you find useful in twig.

Actually, I am quite puzzled with the original ObjectDatastoreFactory:
  • It contains a register method which does something similar, but not quite the same as AnnotationConfiguration.register
  • It contains a getConfiguration method, but no way of supplying my own configuration
  • It contains some create methods while it is recommended to use
    new AnnotationObjectDatastore() directly
DataStoreFactory.java
CompatibilityConfiguration.java

Alex Rhomberg

unread,
Mar 25, 2013, 5:20:10 PM3/25/13
to twig-p...@googlegroups.com
I realised that the simple autoregistering doesn't really work, as previously unused and therefore unregistered ancestors cannot be found by kindToType()
This would either need a twig-internal kind - classname translation table in the datastore or the reversible kind names used in twig 1.0
still, I would like to see support for automatic registering, because that simplifies casual usage of twig

John Patterson

unread,
Mar 26, 2013, 3:17:41 PM3/26/13
to twig-p...@googlegroups.com
I agree.  The main problem with scanning classes on GAE (slow file access) can be avoided if you jar everything up in WEB-INF/classes and put it in WEB-INF/lib.  I could print a warning if the configuration classes were not stored in a jar but scanning was used.

Reply all
Reply to author
Forward
0 new messages