views:

85

answers:

1

Hello everyone,

I'm developing (another) java web framework for personal use, and in addition to that I also want to develop somekind of persistence framework.

I have already developed and engine that in order to access the table, you must only extend a class and create your fields with the same type and name of those in the table. Ex:

private int id;
private String nome;

So you only need now to build the query and execute. The engine put the values on the right fields.

Recently I've had a quite good experience with Django, wich in order to update, create and filter the table you just need to call .save(), .create(field1=field, field2=213) and, .filter(filterfield=value).

I want to build this to, but I am having some trouble, because the extending class would actually have to write more, fact that I don't want to force. I have had the idea to the extending class write an enum implementing an Interface. So the super class get those fields, along with a private HashMap (the key is the enum) and keep the values, so the client just calls:

String nome = Usuarios.get(Usuarios.fields.name);

To retrieve the value.

Usuarios.update(new Pair(Usuarios.fields.name, "José Leal"), new Pair(Usuarios.fields.sobrenome, "Domingues"));

To update and so on.

Anyone have a better idea? I also use velocity framework, so I would like my field to be accessible by its getter.

ps: I know the existence of hibernate and etc.

+3  A: 

I would suggest that you not force users to extend one of your own classes for their model objects. This locks them out of extending their own classes, and makes them more vulnerable to API changes you might make later.

Seeing as javax.persistence already defines annotations that can be used for mapping properties to a database, I'd suggest instead that you let the users make POJOs for their model objects with annotated properties. That way, along with the other mentioned benefits, you're following an already established standard and thereby lowering the barrier to entry for your users.

Robert J. Walker