On 12 December 2011 05:00, Kevin Meyer - KMZ <[email protected]> wrote:

>
> > I'd imagine this ought to be possible by writing a FacetFactory
> similar...
>
> This might also have been able to solve the earlier problems faced by
> Iain Flynn[1] earlier.
>

Indeed; oh well.



>
> >
> > The CgLibClassProxyFactory (and Javassist equivalent) work by
> (on-the-fly)
> > creating a subclass of the provided class.
>
> Do they operate on *instances* of the class (e.g. after New ), or on
> definitions of the class: If I have
> class Customer {
> }
>
> can I use CgLibClassProxyFactory to runtime create:
> class CgCustomer extends Customer implements Persistor {
> }
>
> so that Cayenne can call "newInstance" and create an instance of
> CgCustomer ?
>
>
They work on definitions of the class.

However, I think I gave you bad information there.  Was just digging into
the code, and the CgLibClassProxy is only used by the wrapping domain
container, which is part of the infrastructure for the JUnit test runner.

The class I should have cited is the CgLibObjectFactory (and its javassist
equivalent).  This implements ObjectFactory interface, and is accessible
directly from the PersistenceSession.

For example, CgLibObjectFactory has:

public class CglibObjectFactory extends ObjectFactoryAbstract {
    private ObjectResolveAndObjectChangedEnhancer classEnhancer;

    @Override
    public void open() {
        ...
        classEnhancer =
            new ObjectResolveAndObjectChangedEnhancer(objectResolver,
objectChanger, getSpecificationLoader());
    }

    @Override
    public <T> T doInstantiate(final Class<T> cls) throws
ObjectInstantiationException {
        return classEnhancer.newInstance(cls);
    }
}


where


public class ObjectResolveAndObjectChangedEnhancer extends
ObjectResolveAndObjectChangedEnhancerAbstract {
   ...
    public <T> T newInstance(final Class<T> cls) {
        final Enhancer enhancer = lookupOrCreateEnhancerFor(cls);
        return (T) enhancer.create();
    }

    private Enhancer lookupOrCreateEnhancerFor(final Class<?> cls) {
        Enhancer enhancer = enhancerByClass.get(cls);
        if (enhancer == null) {
            enhancer = new Enhancer();
            enhancer.setSuperclass(cls);
            enhancer.setInterfaces(ArrayUtils.combine(cls.getInterfaces(),
new Class<?>[] { CglibEnhanced.class }));
            enhancer.setCallback(callback);
            enhancerByClass.put(cls, enhancer);
        }
        return enhancer;
    }
}

That "setInterfaces" call is the one that's of interest to you.

~~~
In terms of implementation, you could either clone the entire
implementation and edit in isis.properties, or you could perhaps add some
new configuration keys, eg:

isis.persistor.object-factory=org.apache.isis.runtimes.dflt.bytecode.dflt.objectfactory.CglibObjectFactory
isis.persistor.object-factory.interfaces=org.apache.cayenne.foobar.SomePersistor





> > ~~~
> > Just another thought; I know you have a distaste of the JPA annotations
> > etc, but even so my JPA object store - currently mothballed because it
> has
> > a dependency on the LGPL Hibernate library - might be easier to get fully
> > working, probably by porting to OpenJPA [1].  My view, for what it's
> worth,
> > is that JPA is more mainstream than Cayenne (and would help Isis grow its
> > userbase if we had it as a supported object store....).
>
> The other option could be to provide a decorator / annotator service to
> automagically add annotations based on assumptions, similar to how
> the SQL objectstore creates automappers at the moment?
>

Maybe.  That might be trickier to do, though (it wouldn't be similar to
anything we've done thus far, at any rate).



>
> And what about JDO?
>

JDO is also fine with me; we have a JIRA ISIS-14 to do something in this
space.

HTH
Dan



>
> > I think that Mark is involved in OpenJPA - Mark, can you comment on how
> > OpenJPA picks up its metadata: is it only annotations, or is it
> optionally
> > XML, or even can it just infer some stuff?
> >
> > [1] http://openjpa.apache.org/
>
> [1] http://isis.markmail.org/message/z6ssovojrniuttkd
>
>

Reply via email to