views:

164

answers:

3

Hi all,

Is this possible somehow?

@Name("geolocationService")
public interface GeolocationService
{
   @Query("SELECT g FROM Geolocation geolocation INNER JOIN geolocation.deployment deployment WHERE geolocation.ipStart <= INET_ATON(:ipAddress) AND deployment.active = TRUE")
   Geolocation findByIpAddress(@NamedParameter("ipAddress")final String ipAddress);
}


public GeolocationAction
{
  @In
  private GeolocationService geolocationService;

  @RequestParameter("ipAddress")
  private String ipAddress;

  @Out
  private Geolocation geolocation;

  public void find()
  {
    geolocation = geolocationService.findByIpAddress(ipAddress);
  }
}

Is it possible to do this without implementing the interface? What is required to make that work? I want to maintain less and do more.

If I can intercept invocations of the geolocationService then I am golden, how would I do that? I don't want it to ever be instantiated, so it will always be null (I don't want the @Name and @In annotations either then).

Walter

A: 

First of all an interface is not supposed to be a seam component. How will you instantiate that seam component (interface)?

Secondly. You cannot use @Query like that.

Third, what are you actually asking? I don't understand your question.

Shervin
@Query is my annotation. In a later iteration, I was simply using NamedQuery annotations and then creating the named query based on the method name.It doesn't need to be a Seam component, I just want to give a query parameters without having to write the implementation which will be redundant work.Walter
I was originally thinking about writing a startup listener that would create the necessary queries / components, but all I want is a parameterized method without writing the method itself. In another project I worked on, we used interceptors to automatically get the appropriate query and pass in the arguments from simply an interface. I would do that approach if I felt the interceptor would not add too much overhead.
A: 

I don't really know what Seam is and I don't see a nice simple one paragraph description so I might be talking about something completely irrelevant.

I've have played a little with an idea like for running SQL procedures using nothing but a few annotations. The implementation comes from a dynamic proxy.

mlk
Yeah, I do need dynamic proxies - I am using JBoss Seam with Javassist, so I would probably need to read up on Javassist or JBoss AOP at the very least.I would also like to run some comparisons to see how much overhead it entails for running the exact same query. For a long while, I used Seam Entity Queries which are configured via XML, or as I did, I wrote my own startup listener which created them from annotations. In addition, you can also extend the class and statically set your query there.I like the idea of named queries being declared, but not necessarily on the entity bean.
+1  A: 

For the time being, I wrap all methods in my services. I automatically find the query they're looking for and inject the parameters (either named or indexed). This isn't as clean as I'd like it, but there is room for improvement.

I write an interface as well as a implementation with no code in the body except return(null);

Walter