Is there a maven plugin that will generate RequestFactory EntityProxy classes from my domain classes? - google-app-engine

I am looking for a maven plugin that will auto generate EntityProxy interfaces from my domain classes.
The class could implement the various interfaces to be generated and then each field or accessor method could use an annotation.
public class MyDomainObject implements MyDOProxyFoo, MyDOProxyBar {
#ExposedBy({MyDOProxyFoo.class})
public String foo;
#ExposedBy({MyDOProxyBar.class})
public String bar;
#ExposedBy({MyDOProxyFoo.class,MyDOProxyBar.class})
public String foobar;
...
}
Then the getters/setters for the respective fields would be in the respective generated interfaces.
You could do something like a readonly attribute in the annotation to only expose a getter in the specified interfaces.
...
#ExposedBy({MyDOProxyBar.class}, readOnly = {MyDOProxyFoo.class})
public String bar;
...
I could run something like
mvn rfproxygen:generateproxies
and I would have all my proxy interfaces nicely created in the generated sources directory.
I guess the argument is deciding wether you should have service data binding logic in your domain model.

I don't know a maven plugin that is capable of generating proxies but there is an issue addressing this for GWTP. Maybe this will of interests for you if it's finished.

Related

MongoTemplate vs MongoOperations which one to use

In my project we are using MongoTemplate, which is injected by spring
private final MongoTemplate mongoTemplate;
I know mongo template implements MongoOperations, ApplicationContextAware, so we get context aware method with template, which we do not get if I use the mongo operation type object like below (spring will inject mongo template object in it)
private final MongoOperations mongoOperations;
My doubt is
1. Are we not violating "programming to interface" paradigm doing that
2. Which pattern should we use and why?

ApiTransformer for parametrized, unavailable type

I'm using Objectify and wish to have its Key<> type passed around in my API. I've created an ApiTransformer, but my questions is where to declare it, since the serialized Key<> class is not available, hence I cannot declare its transformer as a class annotation. I tried declaring it in the #Api annotation, but it doesn't work, I still get the error:
There was a problem generating the API metadata for your Cloud Endpoints classes: java.lang.IllegalArgumentException: Parameterized type com.googlecode.objectify.Key<[my package].User> not supported.
The ApiTransformer looks like:
public class KeyTransformer implements Transformer<Key<?>, String> {
public String transformTo(Key<?> in) {
return in.getString();
}
public Key<?> transformFrom(String in) {
return Key.valueOf(in);
}
}
And in my #Api I have:
#Api(name = "users", version = "v1",transformers = {KeyTransformer.class})
Unfortunately you can't. As you said you need to declare it on the Key class, your only chances to make this work are either.
1) Recompile the Key class for objectify with the #transformer annotation.
2) Extend the Key class with your own implementation and define the transformer there.
I don't really like any of those options so the way i usually resolve this is to hide the key object getter (by using #ApiResourceProperty(ignored=AnnotationBoolean.TRUE)) and only expose the id from that key.
That way you get a Endpoints frendly object, the only downside is you'll have to reconstitute the key using Key.create(YourClass.class, longId) manually whenever you need it.
You can add transforms to 3rd party classes by listing the transform in #Api annotation. I'm not dead sure it'll work parameterized class, but I don't see why not.
https://cloud.google.com/appengine/docs/java/endpoints/javadoc/com/google/api/server/spi/config/Api#transformers()

Silverlight+ WCF Ria Service + FK object member is marked with XmlIgnore, can I prevent this from being added to the generated file?

Using silverlight 4, with RIA Services Toolkit May 2010.
I have an Entity Data Model (.edmx) which contains a FK reference.
In my DomainContext Service class (which references my .edmx) I modified my GET method to include Include("FK_ENTITY_TABLE_NAME"):
public IQueryable<PARENT_ENTITY> GetPARENT_ENTITY()
{
this.ObjectContext.PARENT_ENTITY.Include("FK_ENTITY_TABLE_NAME");
}
In my DomainContext Service Metadata class (.metadata.cs) named "internal sealed class PARENT_ENTITYMetadata" I added the [Include] attribute to the
property which references my FK entity:
[Include]
public FK_ENTITY_TABLE_NAME { get; set; }
My generated (.g.cs) ria service proxy file contains the following DataContract with XmlIgnore:
private EntityRef<FK_ENTITY_TABLE_NAME_PARENT_ENTITY> _fk_entity_table_name;
public sealed partial class PARENT_ENTITY : Entity
{
...
[Association("FK_ENTITY_TABLE_NAME_PARENT_ENTITY", "entity_id", ",entity_id", IsForeignKey=true)]
[XmlIgnore()]
public FK_ENTITY_TABLE_NAME FK_ENTITY_TABLE_NAME
{
...
Therefore, when I use the XmlSerializer / DataContractSerializer and on my PARENT_ENTITY, it skips right over serializing my "FK_ENTITY_TABLE_NAME entity:
<PARENT_ENTITY>
(note: no FK_ENTITY_TABLE_NAME serialized here)
</PARENT_ENTITY>
Is there anything i can do to control the XmlIgnore attribute from being inserted in these generated files?
I'd suggest first off to fix your naming convention. Other than that make sure that you expose a get method for your DATA_ENTITY class so that it gets compiled into the generated code.
Also, why is your include for FK_ENTITY_TABLE_NAME but the entity class uses DATA_ENTITY? That seems strange to me. Is there any other relevant code you haven't included?

How do I have a method or property on the model in the server also get generated in the client?

I've got an application set up with RIA Services, Entity Framework 4, and Silverlight 4. It is set up in the standard fashion prescribed on MSDN here: Walkthrough: Creating a RIA Services Solution
I've written a new method (or property) against one of the entity objects which resides on the server; I would like this method (or property) to also be generated (automagically) on the client. i.e.
I have a table in my database called Customer which has two fields: FirstName and LastName
(ASP.NET project - server side) EF has created a corresponding partial class called Protocol that has two properties: FirstName and LastName
(ASP.NET project - server side) In another file, I'm using the partial class mechanism to define a method (or property) to return the FirstName and LastName together in a string, e.g.
public function ReturnFullName() as String ...
public property FullName() as String ...
Is there a way for ReturnFullName() and FullName() to be generated in on the client side (my Silverlight application)? Or do I have to implement the method / property on the client side as well?
Create a .shared.cs or .shared.vb file with a partial class of the entity in it.
For example:
Partial Public Class Persoon
Public Function GetFullName() As String
Return Me.Voornaam & " " & Me.Naam
End Function
End Class
public partial class Persoon
{
public string GetFullName()
{
return this.Voornaam + " " + this.Naam;
}
}
It will then generate on client side to.
Methods in your Domain objects on the server side are not generated on the client side. (One reason for that is that obviously you could use .NET Framework features in these methods that are not available in Silverlight.) Properties are just copied with their signature, using class variables.
A solution to that problem is having a partial .cs file for your Customer class where you define these methods and create a link to that file in your Silverlight project. Of course, you can only use libraries in the using statements that are also available in Silverlight.

Considerations when architecting an extensible application using MEF

I've begun experimenting with dependency injection (in particular, MEF) for one of my projects, which has a number of different extensibility points. I'm starting to get a feel for what I can do with MEF, but I'd like to hear from others who have more experience with the technology. A few specific cases:
My main use case at the moment is exposing various singleton-like services that my extensions make use of. My Framework assembly exposes service interfaces and my Engine assembly contains concrete implementations. This works well, but I may not want to allow all of my extensions to have access to all of my services. Is there a good way within MEF to limit which particular imports I allow a newly instantiated extension to resolve?
This particular application has extension objects that I repeatedly instantiate. I can import multiple types of Controllers and Machines, which are instantiated in different combinations for a Project. I couldn't find a good way to do this with MEF, so I'm doing my own type discovery and instantiation. Is there a good way to do this within MEF or other DI frameworks?
I welcome input on any other things to watch out for or surprising capabilities you've discovered that have changed the way you architect.
Is there a good way within MEF to
limit which particular imports I allow
a newly instantiated extension to
resolve?
Load the extension code in a separate container, and make sure that the restricted parts are not available in that container. Let's simplify the situation to these classes to construct an example:
[Export]
public class MyExtension
{
[Import]
public PublicService Service { get; set; }
}
[Export]
public class PublicService
{
}
[Export]
public class InternalService
{
}
[Export]
public class Program
{
[Import]
public MyExtension Extension { get; set; }
[Import]
public PublicService Service1 { get; set; }
[Import]
public InternalService Service2 { get; set; }
}
The goal is to allow MyExtension to import PublicService, but not InternalService. Internal code like Program should be able to import anything. You can achieve that like this:
var publicCatalog = new TypeCatalog(typeof(PublicService), typeof(MyExtension));
var publicContainer = new CompositionContainer(publicCatalog);
var internalCatalog = new TypeCatalog(typeof(Program), typeof(InternalService));
var internalContainer =
new CompositionContainer(internalCatalog, publicContainer);
var program = internalContainer.GetExport<Program>();
This code will not throw a composition exception. If you now change the import on MyExtension to the forbidden InternalService, you will get a composition exception as desired.
A side effect of this set-up is that PublicService cannot import any private services either, just like MyExtension. This kind of makes sense, because otherwise nothing would stop PublicService from exposing a private service via a property.
I have used TypeCatalog for the example, but in practice you should probably use something like the FilteredCatalog sample.
This particular application has
extension objects that I repeatedly
instantiate. I can import multiple
types of Controllers and Machines,
which are instantiated in different
combinations for a Project. I couldn't
find a good way to do this with MEF,
so I'm doing my own type discovery and
instantiation. Is there a good way to
do this within MEF or other DI
frameworks?
You might just be after the PartCreationPolicy attribute, which controls whether a part is shared (as in, created only once per container) or instantiated multiple times for each import. You can also specify the RequiredCreationPolicy parameter in an import attribute.
If that doesn't solve your problem, take a look at the PartCreator sample in the MEF sources (though note that it will probably soon be renamed to ExportFactory, it already has been in the silverlight edition of MEF).

Resources