Niclas Hedhman wrote:
> But client code should not use this directly. Instead I suggest we
> introduce a new method in QueryBuilderFactory (and possibly change
> name of this to QueryFactory);
> 
>     <T> Query<T> newNamedQuery( String name, Class<T> resultType );
> 
> Now, I have the building blocks in Qi4j API to allow me to do the
> above mentioned use-case.

It seems like NamedQueryService (and I would suggest to call it 
QueryFinder since I think *Service should be reserved for actual 
instances rather than API's) is being called by Qi4j, and should 
therefore be in SPI and not API. Other than that it seems ok.

> This is the foreign interface that I have no control over;
> 
> public interface Abc
> {
>     Habba findHabbaFromName( String name );
> }
> 
> Then I create a Mapping interface to provide some annotations;
> 
> public interface AbcMapping extends Abc
> {
>     @QueryMethod
>     Habba findHabbaFromName( @VariableName( "name" ) String name );
> }

There is a @Name() annotation already for this purpose, so please use 
that. Other than that, looks ok.

> (@QueryMethod can also take the name of the query as the value() argument)
> 
> And to set it up, one would need a ServiceInstanceFactory
> 
> public class AbcServiceFactory
>     implements ServiceInstanceFactory
> {
>     public Object newInstance( ServiceDescriptor serviceDescriptor )
>         throws ServiceInstanceProviderException
>     {
>         // Get the foreign instance.
>         Abc service = ServiceFactory.getService( Abc.class );
> 
>         QueryBuilder<BeanServiceComposite> builder =
>             cbf.newCompositeBuilder( BeanServiceComposite.class );
>         builder.use( AbcMapping.class );
>         builder.use( service );
>         return builder.newInstance();
>     }
> 
>     public void releaseInstance( Object instance )
>         throws ServiceInstanceProviderException
>     {
>         ServiceFactory.releaseService( instance );
>     }
> }

Ahaaa... this is how you provide @Uses. Clever!

> And one could now use the Abc web service as if it was a named query;
> 
> @Structure QueryBuilderFactory factory;
> 
> :
> Query<Habba> query = factory.newNamedQuery( "findHabbaFromName", Habba.class 
> );
> Habba habba = query.find();

Looks ok so far.

> Ok, that is my plan, and I am half way through it, but would like some
> feedback before getting into the really gritty details. For instance,
> I have ignored the relationship with an EntityStore for now, but
> Rickard and I have done a 2min discussion on the whiteboard (but I
> can't recall the details) without any definitive answers but some
> vague intentions of creating temporary Identities for queried
> instances and so forth. More on that later.

Yeah, and I think I would still suggest to do it that way.

> Oh, Habba in the above example, is then potentially back by the
> JavabeanSupport that I have done over the last few weeks, so that no
> transfer objects needs to be created, and we can stick a Qi4j facade
> on the pojo itself.

Looks good, all in all, especially if you can get it to work as an 
EntityStore!

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to